Previously, you came to know that SSH access requires to upload the public key and enable it in the hosting account. Here, you will know how to configure the SSH key in WHM/cPanel and manage the server or your hosting account using key-based authentication.
This tutorial is a part of the ultimate SSH guide. There we have created a key and it needs to be saved and activated in the server management software (WHM/cPanel here). I encourage reading that guide first.
WHM/cPanel offers two ways to set up and enable SSH access:
- Generate a new public/private key pair
- Importing an existing SSH key
Use the first option when you don’t already have public/private keys generated from any other tool like PuTTYgen. The import feature is there when you have already created them outside WHM/cPanel as we did in the SSH setup guide.
SSH Access for root User in WHM
If you have purchased a server or virtual private server with a cPanel license then you would have the access to WHM software as well. Web Host Manager (WHM) provides administrative control on the server while cPanel lets individual users manage their hosting accounts on it.
Hence if you wish to enable SSH for the root user then it requires configuring the SSH key in WHM instead of cPanel.
The steps to generate or import a key in WHM and cPanel are the same. The only difference is the location of the page where these options are present in each of both.
In WHM, we can generate a new key or import an existing key from the links on the Security Center → Manage root’s SSH Keys page.
In cPanel, scroll to the SECURITY section and click the SSH Access link there. On the next page, click the Manage SSH Keys button. Here the same options are present.
1. Generate a New Key
cPanel can generate a pair of public and private keys for you. Later, you can download the private key (in .ppk format) and use it in PuTTY or any other client for SSH into the server.
Press the Generate a New Key button on the Manage SSH Keys page. You will reach the next page with the title “Generating a Public Key”. Choose the following settings for the Key:
- Name: Give the key a name or leave the default (id_rsa).
- Password: Enter a password for the key and confirm it.
- Type: RSA (Default)
- Size: 2048 (Default)
Click the Generate Key button. You will see the “Key Generation Complete!” confirmation message with some details.
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is:
Download Private Key in PPK Format
Click the View/Download link to the respective private key on the Manage SSH Keys page. Enter the passphrase to unlock the private key. You will see the key to be used in PuTTY.
Click the Download Key button and save the PPK file to your computer. Now you can specify the path to this file in the PuTTY as shown in the linked guide.
2. Import SSH Public Key in cPanel
Since we have already generated the public/private key pair using PuTTYgen, we will import the public key here. Click the Import Key button on the Manage SSH Keys page. It will present a form.
The Import SSH Key form gives us the flexibility to store a public or private key. But don’t submit both keys there. Also, the recommended way is, saving the public key on the server and keeping the private key on your PC.
So start with giving a name that can let you identify the imported key later. Then copy the public key either from PuTTYgen or the file in your computer and paste it into the last text box of the form.
Also, there is no need to input the private key or passphrase. Finally, click the Import button.
Enable SSH Access in cPanel
Despite which method you have used to add the key, you must authorize the public key to enable SSH access through it.
Go back to the Manage SSH Keys page. There the list will show the public key recently added. Click the Manage link at the rightmost and authorize it on the next page.
We have set up the SSH key in cPanel. Now we can go back to the article and continue with attaching the private key to the server profile in PuTTY.