Prepare AMI for AWS Marketplace – Reset Linux ec2 Image – delete public keys, etc

Visits: 2137

When preparing a public AMI for AWS EC2, you need to delete lots of security stuff, like public keys, hosts and history. Run this as ec2-user

login to a new session, as even after all of this your commands from this session are only written to the bash_history file when exiting.

sudo rm ~/.ssh/authorized_keys /home/ec2-user/.ssh/authorized_keys /root/.ssh/authorized_keys /root/.ssh/known_hosts ~/.ssh/known_hosts /home/ec2-user/.ssh/known_hosts
sudo shred -u /etc/ssh/*_key /etc/ssh/*
sudo shred -u ~/.*history
shred -u ~/.*history

Also see from our Blog:

Reset AWS AMI Windows 2016 and 2019 Password for use in Marketplace

Follow and this