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

Visits: 3283

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/*_key.pub
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 https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/building-shared-amis.html and this https://docs.aws.amazon.com/marketplace/latest/userguide/best-practices-for-building-your-amis.html

https://docs.aws.amazon.com/marketplace/latest/userguide/product-and-ami-policies.html