Wednesday 9 August 2023

SSH (Secure Shell)

 What is ssh?

SSH is a network protocol by which two machines can communicate with each other, we can transfer information or data from client and server in a secure way.

It uses encryption to secure the data that travel over the network to secure it.

Use of ssh:

We can access a remote machine using ssh over the same network.

Command: ssh <user>@<ip>  eg: ssh root@

Now there are two types of authentication methods that we can use :

  1. Password-based authentication
  2. Key-based authentication
  • In Password-based authentication, we need the password of the host to access it.
  • In key-based authentication, we need keys on the machines ie private and public keys.

How to generate keys.

Command: ssh-keygen 

It generates two keys private key(id_rsa) and public key( at ~/.ssh/

  • Private is private to our local machine, this should never be shared with others.
  • Public key can be shared with other servers/machines. We can copy our public key to a host/server using ssh-copy-id <user>@<ip> or if we can access the UI of the server, we can even upload it there as in GitLab, GitHub. 
The public keys are copied at  ~/.ssh/authorized_host on the server side. When we have our public key shared with the server, we don't need the password to access it, it will be passwordless login from the client. Authentication will be done on the key pair which we added earlier.