Create a passwordless user with .pem file for ubuntu: AWS EC2

Photo by Caspar Camille Rubin on Unsplash

Ec2 is the backbone if you are using AWS cloud infrastructure. by default, you get ubuntu as a user which initially you might have to share with developers to let them access account.

However when your team expand, you should create individual user for each of them with their own keyfile, in case of any compromise, you can terminate user instead updating public and private keyfile for default user.

Lets get into the steps how you can create new user, add key file, and make passwordless login to you aws ec2 server.

If you want to create a user without password, use the following command

Issue following command in your home directory

This will create two files

  1. filename

Rename filename to filename.pem

Run command & display content of the private key file.

Copy its content, on your local system, create newkeyfile.pem and paste the same, this will be used to login to the server using SSH.

Create directory .ssh in your home directory

Create a file named authorized_keys in .ssh directory

Now, copy the content of key), and paste in authorized_keys.

To add a user to sudo group, run following command

Your user is now part of sudo group, you can now log out to the system, and log in as a new user by ssh,

You can use following command to login

Do make your new_user perform sudo operation without a password, you should do following simple steps.

Login to the ubuntu server as ubuntu user.

Run the following command

in the file you see, add the following line

Replace $USER with username in the above line

Save this file, Now your new user should able to perform sudo operations as well, without a password.

Hope it helps you to quickly create additional user whenever you want.

To delete any of the users except root/ubuntu, you can simply run the command

You should delete this user from the system and thus you can protect their login.

Your suggestions are welcome to further improve the article, please share if you find it useful.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store