SSH: Introduction, How to Secure and Working

Secpy Community
InfoSec Write-ups
Published in
6 min readOct 15, 2022

--

Photo by Clément Hélardot on Unsplash

Written by: anshul vyas

What is SSH?

SSH is an acronym for Secure Shell, and basically, in very simple words, it is a protocol that allows two machines to communicate securely on a network.

History of SSH

In the past, there was a need for communication between two computers or two machines. Then, in the 1960s, telnet was invented, which was also a protocol which allowed two computers or two machines to communicate with each other. It was a great invention But it was not secure, it was easily hackable by sniffers. And as we moved to the internet era, there was a need for some protocol which allowed two machines to be accessed easily over a network. So in the 1990s and 1995, to be very specific, ssh was invented and created and this was a secure way in which two machines could communicate or access data securely over a network.

How SSH is secured

Now the question comes to mind about how SSH is secured because there is encryption involved. It means whenever two machines are connected over SSH, the data exchange between them happens with encryption. So the information which is to be used is encrypted and by encryption it means that the actual data is converted into some ciphertext which is not understandable by humans as well as machines. They are not able to extract the original information because there are some encryption algorithms used for extracting the data.

Now we can understand ssh by a very simple example. Suppose you have a box and it contains some very important data and you do not want it to be accessed by anyone else except your friend. As it is crucial information, you lock the box and you have the key to that lock. You send it to your friend by a third person. As the box is locked, a third person cannot open the box or anyone cannot open the box. When the box reaches your friend, he also does not have a key, so he puts another lock on the box. The third person comes back to you with the box. You open your lock because you have a key for your lock. You send the box to your friend again. When your friend gets the box, he can easily open the box with the key because he has the key for that lock. When he opens the box now, he gets all the crucial information present in the box. And no information was leaked to anyone, and he also got the information securely. This is how information and data can be exchanged in a secure way.

SSH Working

To establish a ssh connection, we need three things, or three components The first one is the server, or the remote machine that we will access from the local machine, and then we need the client, or the local machine, and finally we need an authentication mechanism so that the server can authenticate the client and vice versa. To make any system an ssh server, we need to have ssh running or the system settings must be setup in such a way that it can be connected remotely.

Now this ssh server can be on any system: windows,linux , mac, and it can be even an android or iOS system . Now in this case, if the system is MAC, we just need to allow remote connections on that system. If it is linux or windows, we can install an openssh server and by installing this, our system is ready to be accessed over ssh. And if it is android or iOS, we need some apps which we can run so that it becomes an ssh server or it is ready to be connected remotely. Now that we have an ssh server, we can move on to the client or local machine, which can be a Mac, Linux, Windows, or even an Android or IOS system.

If the local machine is Linux or Mac, we no longer need to install or configure anything; we can simply use our terminal on Mac or Linux as an SSH client. And if it is windows, we can get some ssh client applications like Putty or if we have a GIT Bash command prompt installed so that we can also use that to communicate over ssh, and if it is android or ios, we will find some apps like Termux that can help you connect over ssh. Now we have our ssh server and client ready. Now the third thing is the authentication mechanism .

When we connect to a remote system from our local system using ssh, we have to authenticate this connection. There are two ways this connection can be authenticated. One is using a password and the other one is using keys, which is public key and private key. So, in very simple terms, if we want to connect over SSH to a remote system, It can be explained by the following example: let us say we have ssh user@ip, so this is a very simple syntax of the command. Now a real command will look something like this: say ssh root@165.32.18.18. So when we run this command, we want to access the remote system as the root user.

We will be prompted for a password when we run this command. Once all the authentication is done, we will be able to access the remote system and then we can run our commands on the remote system. Now the other way is to have the keys be public and private keys. If we want to do or create authentication using a public or private key, we can run the command ssh-keygen from our client machine, which will ask us where we want to store or what filename we want to give to our public and private keys. If we want to give some specific name, we can provide the location and name, or if we directly enter, it will take the default name and it will also prompt us to provide a password for our private key.

If we want our private key more secure, he should not be able to use it unless he provides the password set by us. If we don’t want a password, we can directly hit enter on the command line and this will create two keys, a public key and a private key on our system . Now we can send the public key to the server or the remote machine that we want to access and we can just use commands like ssh copy to copy the public key or if our ssh server can be accessed from the browser with the UI, for example, in the case of GitLab or GitHub, we can just open our account on GitLab or GitHub and then go to the ssh section and there will be an option to browse and upload your public key, so we can also do it through the browser if we have that option . So in very simple words, we have to create these two keys and send the public key over to the remote system.

Now after that, we have to setup these keys and we have already sent the public key to the server. After this, whenever we try to connect over ssh using these commands or in any way we try to connect to the remote system using ssh, the authentication will happen using these keys. So, as we try to connect or send the connection request to the server, clients receive a random message from the server, which is encrypted and sent back to the server by the client using its private key.

The server will decrypt it using its public key and if the match is successful, then only the connection will be established. Now we can access the remote system, do any work there, or run any commands. So this is how SSH works and this is how we can securely connect to a remote system and access it or do any work there.

From Infosec Writeups: A lot is coming up in the Infosec every day that it’s hard to keep up with. Join our weekly newsletter to get all the latest Infosec trends in the form of 5 articles, 4 Threads, 3 videos, 2 GitHub Repos and tools, and 1 job alert for FREE!

--

--

SecPy Community aims to change whole environment of Cyber Security and Ethical Hacking with the help of curious minds & build ground-breaking solutions