Hello readers, if you are new to this term ssh
, then this is the blog for you. I’ll cover SSH from basic, laying down its importance and will show you how to configure SSH for remotely accessing a Linux server.
What is SSH and why it is required?
SSH stands for Secure Shell. It is a communication protocol, which helps us in communication with other devices over a network, just like HTTP does. So what’s the difference? It is known for sending encrypted data over the network so that it can be prevented from unauthorized access. It runs on port number 22 by default. SSH first ensures the authenticity of the client and then build a pipeline between the SSH client and the server. Data transmitted through this pipeline is encrypted by using the concept of Asymmetric Data Encryption. To know more about asymmetric encryption, you can refer to this video on Asymmetric Encryption.
When to use SSH?
Following are the use cases for using SSH.
- For transferring some data securely over the network.
- Get access to a remote server.
Configuring SSH on Linux server
As we know that we can use SSH to get access of a remote server, I’ll show you how to configure SSH on a Linux machine. To excess any remote Linux machine through SSH, it must be configured with OpenSSH daemon (SSHD) which allows that remote machine to act as an SSH server.
Following is the command to install SSHD:
sudo apt-get install openssh-server
This will allows the machine to listen to ssh connections. Now we can get access of that remote machine by using the following command:
ssh <userid>@<IPaddress>
After adding this, you will be prompted for allowing your client machine to get access to the remote server. Enter yes
to add the server to your list of known hosts stored at ~/.ssh/known_hosts
. Then it will ask for the password of that system. As passwords can be easily stolen or can be accessed by the bruteforce attack, we want SSH authentication for which we need to have a pair of public and private key.
SSH key pair generation
To generate a pair of RSA keys, the command is :
ssh-keygen
The keys will be generated as follows:
- Private key:
~/.ssh/id_rsa
- Public key:
~/.ssh/id_rsa.pub
These generated keys will be encrypted using RSA cypher method. To use any other cypher technique, you need to use -t
flag as follows:
ssh-keygen -t dsa
Now for SSH authentication, we need to add our public key to remote machine’s authorized_hosts
file. For this, we will use scp
command which means secure copy.
scp ~/.ssh/id_rsa.pub userid@IPaddress:~/.ssh/authorized_keys
This will successfully configure the SSH and now you will have the access to the remote machine through your SSH client which is your CLI.
After going through the contents, now you’ll be familiar with the concept of SSH, why it is used and how to configure it for accessing a remote server. Still, if you have any queries, feel free to contact me at yatharth.sharma@knoldus.in.
Thank you for sticking to the end. If you like this blog, please do show your appreciation by giving thumbs ups and share this blog and give me suggestions on how I can improve my future posts to suit your needs. Follow me to get updates on different technologies
