Note: replace {{server}} with your domain or ip
- Login as the ec2-user
ssh -i key.pem ec2-user@{{server}}
- Switch to administrator
sudo -i
- Load the configuration file
sudo vi /etc/ssh/sshd_config
- Make sure these are enabled:
PermitRootLogin yes
# Only allow root to run commands over ssh, no shell
#PermitRootLogin forced-commands-only
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
- copy your local public key to the authorized list
cat ~/.ssh/id_rsa.pub | ssh root@{{server}} 'cat - >> ~/.ssh/authorized_keys'
- Make sure the files have the right permisions
chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh/
- Restart the service
sudo service sshd reload
- Exit and try to login again
exit
ssh root@{{server}}
This is awesome. Thank you! (Worked for my Ubuntu instance as well, btw.)