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.
![](/images/img_59cb9ca9404e9.png)
Connect via SSH into your instance using its public IP:
![](/images/img_59cb9ce3697b6.png)
Next, create a new user using the following command:
1 | sudo adduser labouardy |
![](/images/img_59cb9d3fcd438.png)
Next, we switch the shell session to the new account:
1 | sudo su labouardy |
Create .ssh directory, and change the directory permission to 700 (only the file owner can read, write or open the directory):
1 | mkdir .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)
1 | touch authorized_keys |
![](/images/img_59cb9da5c0614.png)
Finally, edit the authorized_keys file and past in your public key:
![](/images/img_59cb9f67204bb.png)
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:
![](/images/img_59cbaad16623a.png)
We now are logged in as user labouardy 😄
Drop your comments, feedback, or suggestions below — or connect with me directly on Twitter @mlabouardy.