DEV Community

Estevez Ben Lajamin
Estevez Ben Lajamin

Posted on • Edited on

How-to-use guide for SSH

If you want to watch the video version of this, here the link (https://youtu.be/lWWlEDRO2uo).

SSH Authentication Methods

  1. Password [Using your server's user's password]
  2. Public/Private Key Pair

Screenshot from 2021-07-09 11-11-42

Don't use root to login. Instead create a new user

Create a new user

adduser chloe[Can be any name]
Enter fullscreen mode Exit fullscreen mode

Screenshot from 2021-07-09 11-25-30

Now add chloe to sudo group

sudo usermod -aG sudo chloe.
Enter fullscreen mode Exit fullscreen mode

Screenshot from 2021-07-09 11-30-12

Since you created a new user, add the public key to that user .ssh folder. It's usually located at /home/chloe. Create a new .ssh folder and create authorized_keys if not exist and paste public key inside.

Screenshot from 2021-07-09 17-51-35

# Login into remote server and navigate to /home/chloe
# Create a new .ssh folder
sudo mkdir /home/chloe/.ssh
Enter fullscreen mode Exit fullscreen mode
# Create file 'authorized_keys'
# Paste client public key inside
# Save it
sudo nano authorized_keys
Enter fullscreen mode Exit fullscreen mode

Next, change the ownership of the folder to chloe.

sudo chown -R chloe:chloe /home/chloe
Enter fullscreen mode Exit fullscreen mode

chown - change ownership
R - Everything
chloe:chloe - user:group
/home/chloe - folder path

Now, on client side, if you're using new public/private key pair then you have to add them.

ssh-add /path/to/privatekey [eg. ~/.ssh/id_rso_new]
Enter fullscreen mode Exit fullscreen mode

[optional]There a possibility that ssh agent inactive. Active by run

eval `ssh-agent -s`
Enter fullscreen mode Exit fullscreen mode

That all. Hope the steps simple enough to understand. Peace :)

Top comments (0)