How to SSH Into a Linux(Ubuntu) Server With a New User Using the Terminal

#cloud   #DevOps  

This is a simple beginner's tutorial where I will demonstrate how to ssh into an Ubuntu server with a new local user.

Why this tutorial; it is to show how different users can ssh into an Ubuntu/Linux server hosted on the Cloud (AWS, GCP, Azure), etc.

Prerequisites

  1. Cloud account (AWS, Azure, GCP, DigitalOcean, or any other cloud provider)
  2. Basic Linux knowledge.

Steps to follow

  1. I will be using AWS to create and launch a new EC2 instance. I choose an Ubuntu Server 20.04 LTS (HVM), SSD Volume Type Amazon Machine Image (AMI), and t2micro instance type which is a free tier instance.
  2. SSH into the newly created server through your terminal.

1_-S2iZjxAk9jiro1cuwIrdA.jpeg

Ubuntu server created

3. Create a new user (chinel) and the goal is to ssh as chinel user instead of Ubuntu user.

1_tzV5uuMP10sQud_Sz89QhQ.jpeg

Creating new user

Note: While creating the new user, remember to use sudo adduser command.

4. Change from the ubuntu user to the new user I created which is chinel using the su command.

1_Q5tZCsCHLQcY5ubp8OfVOQ.jpeg

5. Use the Linux command ls -al to check for .ssh folder which will show you all the files in the directory including hidden files. We will see that there is no .ssh folder in our new user’s list of directories. To fix this, we need to add the public key that exists in the Ubuntu user’s ~/.ssh/authorized_keys file to Chinel user.

6. Logout of the chinel user using exit command. This will take you back to the ubuntu user.

7. Enter into /home/ubuntu/.ssh/authorized_keys and copy the content.

8. Change back to the chinel user and create a new .ssh directory.

1_WYc82lnKWD1ubC670D7juA.jpeg

9. Using vim editor, create a file called authorized_keys inside the .ssh folder and paste the contents from /home/ubuntu/.ssh/authorized_keys copied earlier.

1_u0qUsosqbxq_A7i6_EhzfQ.jpeg

10. Exit and log out of the Ubuntu server.

11. Now I have my .ssh folder and my keys in the authorized_key file and can now ssh into my chinel user directly.

1_lrQF58fCvWQ1SV-c0KBvrw.png

Conclusion

This is is a simple tutorial on how to ssh into an Ubuntu server/instance with a non-default user.

PS: This is my first article on Medium, please like and share. Thank you.

Start blogging about your favorite technologies and get more readers

Join other developers and claim your FAUN account now!

Discussed tools
LinuxKit