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 cPanel, or you can generate the keys yourself and just upload the public one in cPanel 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:

  • Next you will have to type in the location of the file where you would like to save the private key.

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:

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
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/

To use the keys with your SiteGround account, you need to upload the public key in cPanel, under SSH/Shell access.  The private key needs to be loaded in your Terminal using the ssh-add command:

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, please check our articles below:

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

How to Enable SSH for Cloud on Linux

How to Enable SSH for Dedicated Server on Linux