Skip to main content
2 of 2
Added how to fix the permissions if incorrect
Hbar
  • 121
  • 4

One way I get locked out while developing is by changing the permissions on any of the directories or files associated with the keys used by ssh. This happens to me when I untar files or run some installation script while initializing the machine that touches the ec2-user account.

Make sure the permissions are like:

1> ls -ld $HOME $HOME/.ssh
drwx------ 15 ec2-user ec2-user 4096 Aug  1 13:15 /home/ec2-user/
drwx------  2 ec2-user ec2-user 4096 Jun 10 11:18 /home/ec2-user/.ssh/

2> ls -l $HOME/.ssh/authorized_keys
-rw------- 1 ec2-user ec2-user 385 Jun 10 11:18 /home/ec2-user/.ssh/authorized_keys

If not, and you are logged in as ec2-user, you can change them with

sudo chown ec2-user:ec2-user ~ec2-user ~ec2-user/.ssh ~ec2-user/.ssh/authorized_keys
chmod 700 ~ec2-user ~ec2-user/.ssh
chmod 600 ~ec2-user/.ssh/authorized_keys

To protect myself against my own mistakes, I create a new user and copy the ec2-user key over. That account is used as a backup and not part of any script. Once I tested everything, I remove the account.

Hbar
  • 121
  • 4