Hot to Connect to a Linux Server Using SSH Private Key
If you are connecting from a Linux OS or macOS, typically, you would open the terminal and enter ssh [user]@[host] which would then prompt you to enter the password for the user. In this case, [user] represents the account you want to access, for example, root, and the [host] represents the server you wish to access, which can be either an IP address or a domain name.
Windows users, on the other hand, have to download an SSH client such as PuTTY to establish an SSH connection. Within the client, they have to enter the server IP and the SSH port. Afterward, a window will open that will ask you to enter the username followed by the password.
There is, however, another way you could establish an SSH connection without using the username and password. You can connect to SSH with a private key, and today we will show you how it’s done.
How to connect to a Linux server with an SSH private key using PuTTY
First, you will need to install some software on your machine:
We recommend using the PuTTY client to connect to SSH from Windows (these steps can also be done on Linux and macOS as both PuTTY and PuTTYgen are also available on said OS). Both can be installed from the official site with only one installer. Once the software is installed, you are ready to begin the setup.
- Create a text file, paste your SSH private key into it, and save the file. This type of file is called a key file. Do keep in mind that you must also include the BEGIN and END It should look similar to this:
- Launch PuTTY Key Generator (i.e. PuTTYgen)
- Within the Actions menu, click on Load, and select the key file that you created in step 1. If the key is loaded successfully, a confirmation should be displayed. Click on OK to dismiss the message.
- Enter a unique key passphrase into the Key passphrase field and then re-enter it again into the Confirm passphrase You will be prompted for the passphrase whenever you try to connect to the server using the private key (you can also leave them blank, however, it is not recommended)
- Now click on Save private key and enter the file name to be saved as a .ppk file.
- You can now close PuTTYgen and open PuTTY itself.
- Enter the server’s IP address into the Host Name (or IP address) field and the corresponding port into the Port Do not forget to select SSH under Connection type. Lastly, enter the name for the session under Saved Sessions and click on Save.
- Within the left navigation pane, click on Connection > Data and type root in the Auto-login username If you wish to access a different user, enter that user instead.
- Go back to the left navigation pane and click on Connection > SSH > Auth. You will see the options that control the SSH authentication. Under the Private key file for authentication click on the Browse… file button and select your .ppk file generated in step 5.
- Return to the starting page by clicking Session in the left navigation pane and click on
- Click on Open and establish your connection to the server.
And that is how you set up an SSH connection to a Linux server via the SSH private key. Since we named and saved the connection (steps 7 and 10, respectively), we can now choose it from the saved sessions list at any time and use it without having to repeat all of these steps. If you found this tutorial useful or need some help, we encourage you to leave a comment on the article.