Access EC2 Linux box over ssh without .pem file

You may be in the situation where you need to access your EC2 instance from any machine, not necessarily your own. It's a pain to carry around your .pem file and a bad idea to leave it on someone elses machine too. Here's a solution to let you login to your instance with a password. Please be aware that this is less secure (thanks rnhurt for pointing this out) than using keys, so be sure to create a strong password.
1. Login to your EC2 instance using your .pem file
ssh -i your_pem_file.pem ubuntu@ec2-________.compute-1.amazonaws.com
2. Create a new user that will access the instance using a password:
$ sudo useradd -s /bin/bash -m -d /home/USERNAME  -g root USERNAME
where:
  • -/bin/bash : use /bin/bash as the standard shell
  • --/home/USERNAME : create a home directory at /home/USERNAME
  • -g root : add to group root
  • USERNAME : the username of the new user
3. Create a strong password for the new user:
$ sudo passwd USERNAME
Enter new UNIX password:
Retype new UNIX password:
4. Add user to sudoers file by using sudo visudo and add the following line:
USERNAME  ALL=(ALL:ALL) ALL
5. Enable password authentication by editing /etc/ssh/sshd_config: change PasswordAuthenticationno to PasswordAuthentication yes
6. Restart ssh:
sudo /etc/init.d/sshd restart
Logout of your instance (exit) and try your new login without the .pem file:
$ ssh USERNAME@ec2-________.compute-1.amazonaws.com
USERNAME@ec2-________.compute-1.amazonaws.com's password:

Comments

Popular posts from this blog

Default ssh Usernames For Connecting To EC2 Instances

Deleting a Route 53 Hosted Zone And All DNS Records Using aws-cli

JAWS: THE JAVASCRIPT + AWS STACK.