DEV Community

Estevez Ben Lajamin
Estevez Ben Lajamin

Posted on • Edited on

2 1

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 :)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs