Secure Shell (SSH) is a network protocol utilized to connect to a remote computer via the public-private key securely. It is commonly used to log in to remote servers, execute commands, and transfer files.
This tutorial will illustrate the step-by-step procedure to establish a remote connection using the private key. The content of this article is given below:
Let’s follow the article’s content.
How to SSH Using a Private Key in Linux?
The “ssh” command is used to connect with the remote system using SSH protocol. It allows you to execute commands remotely, transfer files, and even create secure tunnels between computers. A step-by-step procedure is mentioned below to make a connection using the private key:
Step 1: Generate an SSH key pair
The SSH key pair is generated on a local machine, executing the “ssh-keygen” command. It creates a private key file (usually named id_rsa) and a public key file (id_rsa.pub).
The public key is shared with the server and is utilized to encrypt messages. The client decrypts it via the private key. The public key is also used to verify digital signatures created with the private key:
The private key has been saved in the “/home/itslinuxfoss/.ssh/id_rsa” file.
Step 2: Copy the Public Key
Copy the public key to the remote device. Execute the “ssh-copy-id” command by specifying the username and hostname of the remote machine:
$ ssh-copy-id roger@ubuntu
The output shows that the key has been successfully added.
Step 3: Connect to the Remote Machine
Connect to the remote machine using SSH and the private key. To do this, you will need “username” and “hostname” by specifying the private key file “ssh/id_rsa” with the “-i” option:
$ ssh -i ~/.ssh/id_rsa roger@ubuntu
The returned output shows that the connection has been established.
Alternative: Access Remote Machine via IP Address
Users can access the remote machine using the server IP address of the local system. This way, users do not have to specify the private key whenever connecting to the remote machine. To do so, the IP address of the remote user is required with the username:
$ ssh [email protected]
The output confirms that the connection has been successfully established.
Note: The private key file must be kept secure and should only be accessible to the user who generated it. It should also be protected with a passphrase to prevent unauthorized access.
That is all from the guide to creating a connection using SSH.
To make a remote connection using the private key, first generate the SSH key pair. Furthermore, add the public key to the remote device. Finally, establish a connection to the remote server by executing the “ssh -i ~/.ssh/id_rsa username@hostname” script. This article has explained all the steps to SSH using the private key.