paint-brush
Add new users to EC2 and give SSH Key accessby@mlabouardy
22,045 reads
22,045 reads

Add new users to EC2 and give SSH Key access

by Mohamed LabouardyOctober 26th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

In this quick post, I will show you how to add a new user to an <strong>EC2 instance</strong> and <strong>SSH</strong> with your own <strong>private key</strong> rather than having to authenticate using the private key generated by <strong>AWS</strong>.
featured image - Add new users to EC2 and give SSH Key access
Mohamed Labouardy HackerNoon profile picture

In this quick post, I will show you how to add a new user to an EC2 instance and SSH with your own private key rather than having to authenticate using the private key generated by AWS.

Connect via SSH into your instance using its public IP:

Next, create a new user using the following command:

|sudo adduser labouardy

Next, we switch the shell session to the new account:

|sudo su labouardy

Create .ssh directory, and change the directory permission to 700 (only the file owner can read, write or open the directory):

|mkdir .ssh

|chmod 700 .ssh

Note: ensure you are in the new user’s home directory (example: /home/labouardy)

Create an empty file called authorized_keys in the .ssh directory and change its permissions to 600 (only the file owner can read or writ eto the file)

|touch authorized_keys

|chmod 600 authorized_keys

Finally, edit the authorized_keys file and past in your public key:

Once you’ve done this, exist out back to your machine, then try to SSH using the the new credential and user account you’ve created:

We now are logged in as user labouardy