How to connect via SSH using keys


Your SSH session can be authenticated either with the username and password or with a pair of private/public keys. It is recommended to use the latter, as it is considered to be a more secure and convenient solution:

For cPanel Basic Theme

For cPanel Retro Theme

For cPanel Basic Theme:

1. Manage SSH Keys

2. Create a new pair of SSH keys

3. Import of the existing keys

4. Use Putty and SSH key pair to connect

 

1. Manage SSH Keys

In cPanel you can manage SSH keys in the SSH access menu.

Click on Manage SSH keys:

On the next page, you can either import the existing pair of keys or generate a new one.

2. Create a new pair of SSH keys

2.1. Public and private keys generation

In order to generate a new SSH key pair click on the Generate a new Key option:

On the generator page, specify the password (passphrase), Key Name, Key Type and Size.
The maximum allowed DSA key size is 1024 which is not enough to guarantee its security nowadays. That’s why we suggest using only RSA with 2048 bits:

Once everything is set, click Generate Key.

Now you should see both private and public keys you created.

2.2. Public key authorization

In order to authorize SSH access to your hosting account by the private key you created, click on the Manage option:

On the next page, click on the Authorize button:

2.3. Acquiring a key pair

You can view and download keys you have in cPanel by clicking on the View/Download button in the Private Keys section:

Click on Download Key (it will be saved in a simple text document on your side) or just copy/paste the provided key if needed. You can also convert your key into PuTTY’s ppk format using the Convert option:

The steps for generating keys via SSH can be found here.

3. Import of the existing keys

If you already have a key pair generated by other means, you can import the public key using the Import Key option:

Next, fill in the required details:

 

  • Choose a name for this key (defaults to id_dsa): type in id_rsa;
  • Paste the Private Key in this box: leave it empty (this field is only used in cases, where you want to have SSH access from your cPanel account to other servers via the keys);
  • Passphrase: input the passphrase;
  • Paste the public key into the following text box: on your local computer open your public key file (e.g./User/name/.ssh/id_rsa.pub) > copy and paste the content of that file into the field;
  • Click Import

Once done, do not forget to authorize your imported public key in the same way as in step 2.2.

4. Use Putty and SSH key pair to connect

In this example, we will use the Putty SSH client and key pair generated by cPanel in order to access the server via SSH:

4.1. Download the Private key as it is shown in step 2.3.

4.2. In the PuTTy folder, run puttygen.exe; in the top menu select the File tab and click on Load private key and select your private key file (make sure All files (*.*) filter is used so you can see your downloaded private key file):

You will be asked for the passphrase you specified during the key generation in step 2.1. After entering it you should receive a successful import message:

In case you do not wish to set a passphrase for the key, you can empty the Key passphrase and Confirm passphrase fields.
Now click on Save private key and save your key as a .ppk file which will be needed later:

4.3. Run the PuTTy client (putty.exe), select Connection > SSH > Auth and in the Authentication parameters section, click on Browse to select the saved .ppk file:

Once done, get back to the Session section and input the server name (IP address) and specify SSH port (it should be 21098 for all shared servers accounts) and click Open:

In the console window, you will be asked for the login and passphrase:

For cPanel Retro Theme:

1. Manage SSH Keys

2. Create a new pair of SSH keys

3. Import of the existing keys

4. Use Putty and SSH key pair to connect

 

1. Manage SSH Keys

 

In cPanel you can manage SSH keys in the SSH access menu:

Click on Manage SSH keys

On the next page, you can either import the existing pair of keys or generate a new one.

2. Create a new pair of SSH keys

2.1. Public and private keys generation

In order to generate a new SSH key pair click on the Generate a New Key option:

On the generator page, specify the password (passphrase), Key Name, Key Type and Size.
The maximum allowed DSA key size is 1024 which is not enough to guarantee its security nowadays. That’s why we suggest using only RSA with 2048 bits:

Once everything is set, click Generate Key.

Now you should see both private and public keys you created.

2.2. Public key authorization

In order to authorize SSH access to your hosting account by the private key you created, click on the Manage option:

On the next page, click on the Authorize button:

2.3. Acquiring a key pair

You can view and download keys you have in cPanel by clicking on the View/Download button in the Private Keys section:

Click on Download Key (it will be saved in a simple text document on your side) or just copy/paste the provided key if needed. You can also convert your key into PuTTY’s ppk format using the Convert option:

3. Import of the existing keys

If you already have a key pair generated by other means, you can import them using the Import Key option:

Next, fill in the required details:

 

  • Choose a name for this key (defaults to id_dsa): type in id_rsa;
  • Paste the Private Key in this box: leave it empty (this field is only used in cases, where you want to have SSH access from your cPanel account to other servers via the keys);
  • Passphrase: input the passphrase;
  • Paste the public key into the following text box: on your local computer open your public key file (e.g./User/name/.ssh/id_rsa.pub) > copy and paste the content of that file into the field;
  • Click Import

Once done, do not forget to authorize your imported public key in the same way as in step 2.2.

4. Use Putty and SSH key pair to connect

In this example, we will use the Putty SSH client and key pair generated by cPanel in order to access the server via SSH:

4.1. Download the Private key as it is shown in step 2.3.

4.2. In the PuTTy folder, run puttygen.exe; in the top menu select the File tab and click on Load private key and select your private key file (make sure All files (*.*) filter is used so you can see your downloaded private key file):

You will be asked for the passphrase you specified during the key generation in step 2.1. After entering it you should receive a successful import message:

In case you do not wish to set a passphrase for the key, you can empty the Key passphrase and Confirm passphrase fields.
Now click on Save private key and save your key as a .ppk file which will be needed later:

4.3. Run the PuTTy client (putty.exe), select Connection > SSH > Auth and in the Authentication parameters section, click on Browse to select the saved .ppk file:

Once done, get back to the Session section and input the server name (IP address) and specify SSH port (it should be 21098 for all shared servers accounts) and click Open:

In the console window, you will be asked for the login and passphrase:

That’s it!

Leave a Reply