Introduction
Hello!, Today i used ssh to access a remote server and i am really very happy with the result. In this post i am gonna show you how to access a remote server from your linux machine.
Secure Shell, or SSH, is a cryptographic (encrypted) network protocol operating at layer 7 of the OSI Model to allow remote login and other network services to operate securely over an unsecured network.
SSH keys provide a more secure way of logging into a virtual private server with SSH than using a password alone. While a password can eventually be cracked with a brute force attack, SSH keys are nearly impossible to decipher by brute force alone. Generating a key pair provides you with two long string of characters: a public and a private key. You can place the public key on any server, and then unlock it by connecting to it with a client that already has the private key. When the two match up, the system unlocks without the need for a password. You can increase security even more by protecting the private key with a passphrase.
Setting up ssh keys
Create the RSA Key Pair
The first step is creating RSA key pair on the client machine. To create RSA key use –
$ ssh-keygen -t rsa
-t specifies the type of key to be created and rsa specifies the type of key i.e RSA in our case.
Store the Keys and Passphrase
Once we have entered the create key command, we will get a few more questions:
Enter file in which to save the key (/home/username/.ssh/id_rsa):
You can press enter here, saving the file to the user home (in this case, i am using username).
Enter passphrase (empty for no passphrase):
It depends on user if he want to enter passphrase or not. Adding a passphrase increases security but it has one disadvantage, the user has to enter this passphrase every time he uses key pair.
We will get the output as –
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:xBx+KCtj9j7By4CVQdoPeaI+cr8FPNxX6Nrni03b+mc username@name
The key's randomart image is:
+--[ RSA 2048]----+
| .oo. |
| . o.E |
| + . o |
| . = = oo . |
| = S = . |
| o + S= + |
| . o + o . |
| o.oo*. o |
+-----[SHA256]----+
public and private key will be stored in /home/user/.ssh/ as id_rsa.pub and id_rsa.
Connecting to remote server
For this example let us suppose we have the username “demo” on server with ip address “104.131.33.104” with password “password” ( Never keep password this predictable :p).To access the remote server use following command-
$ ssh demo@104.131.33.104
It will then ask password for demo@104.131.33.104. Enter “password” and hit enter.
You are now logged into the remote server.