Wednesday, February 2, 2011

Root login to Amazon EC2 instance

Login to fresh EC2 instance as root can return error: "Please login as the ec2-user user rather than root user". You can login easily as "ec2-user" and execute administration commands using "sudo ..." or just become root using "sudo su". But it's not always comfortable and if you want to login via SSH as root, follow these simple steps.
  1. Edit the /etc/ssh/sshd_config file and change the line that says "PermitRootLogin No" to "PermitRootLogin without-password". Then restart the sshd server with "service sshd restart". Be careful, if you screw up the sshd file, it is possible you will only have your current ssh session to fix it, so always test any changes with a second session.
  2. Edit the /root/.ssh/authorized_keys file. The first (and only) entry starts with "command ... sleep 10; ssh-rsa [big long key]". If you remove the text from the beginning of the line until where it says "ssh-rsa", you will be able to login as root via SSH with your Amazon keypair.

0 comments: