Advanced Site Tools
How to generate an SSH key pair in Linux?

How to generate an SSH key pair in Linux?

SiteGround uses key-based authentication for SSH. This has proven more secure over standard username/password authentication. More information on SSH keys can be found here.

You can generate an SSH key pair directly in Site Tools, or you can generate the keys yourself and just upload the public one in Site Tools to use with your hosting account.

When generating SSH keys yourself under Linux, you can use the ssh-keygen command. To do so follow these steps:

  • Open up the Terminal;
  • Type in the following command:
ssh-keygen -t rsa
  • Next, you will have to type in the location of the file where you would like to save the private key.
Enter file in which to save the key (/home/youruser/.ssh/id_rsa):

The public key will be saved in the same location, under the same file name, but with the .pub extension. Type in nothing to use the default location, which is /home/youruser/.ssh/id_rsa.

  • Finally, you will have to type in a password. This will be the password required to load the private key and use it to connect via SSH later on:
Enter passphrase (empty for no passphrase):

The entire key pair generation process would look like this:

user@localhost: ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/youruser/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
16:8e:e8:f2:1d:c9:b9:cf:43:9a:b3:3c:c1:1f:95:93 user@localhost

This will create a private key written to /home/youruser/.ssh/id_rsa and a public key written to /home/youruser/.ssh/id_rsa.pub.

To use the keys with your SiteGround account, you need to upload the public key in Site Tools > Devs > SSH Keys Manager. The private key needs to be loaded in your Terminal using the ssh-add command:

ssh-add /home/youruser/.ssh/id_rsa

After which you will be asked to enter the passphrase of your key.

For more information on how to connect to your SiteGround hosting account via SSH, check the articles below:

How to log in to my SiteGround shared account via SSH in Linux

Share This Article