Setting up SSH access using keys for cPanel and WHM

The internet has become an extremely unsafe place. Numerous methods of attack are public access and anyone can try them. At the same time, new common vulnerabilities are discovered almost daily. Software developers do their best to close all new vulnerabilities, but it is next to impossible to keep. Bots, bots and more bots are scanning servers for different security holes and once they find one on your server, believe me, they will use 100% of it. Your server will work for proxy, spam sending or even bitcoin mining…maybe even without your knowledge.

GlowHost does it’s best to prevent attacks. We have been providing hosting for many years and have skilled professionals in this area.

Also, GlowHost is working in partnership with security firms and runs daily scans of all servers in order to find suspicious software. We do this day in and day out, constantly, and we are not going to stop. We do our best to secure our customers, because we care.

The latest issue we have noticed floating around the Interwebs is that the SSH service can be easily hacked if password authentication is enabled. At the time of this writing, most hosting companies know about this problem, but are being very quiet about it as there is no known fix other than forced key access, and how the attackers are able to do this is not 100% clear. Because the service has vulnerabilities, we had to close that feature in order to protect our customers. In order to keep this security measure in place, but still allow a secure connection, you can use an SSH key. Below I will describe how to set up SSH access using keys and gain access to the server.

Requesting SSH Access

In order to use SSH on a shared account, you will need to contact our support team to grant you access. It’s simple and painless! Once that’s set up, you’re good to proceed.

Creating SSH keys

First of all, you need to login to WHM (login details are in your welcome letter from GlowHost). In the search field type “Key” (1 in the image example below) to filter the menu options and click on “Manage root’s SSH Keys” (2).

If you don’t have WHM access, you can do the same from cPanel -> SSH/Shell Access. Functions are the same as in WHM.

Now you will see keys set up on your server. Please do not remove keys belonging to the GlowHost technical team. If you do, we won’t be able to access your server and provide you with managed service.

Click on the “Generate a new key” link (3).

Creating keys

Now you will see fields to generate a new key pair. Enter the following information in the respective text box:

Name: Just the name of the key. Usually used to identify the owner.
Key Password: You can keep it blank, but we do advise strongly to create a password so nobody else can access the server using your key.
Key Type: RSA
Key length: No less than 2048 bits for RSA.

ssh_2

Click the Generate button. Keys will be created.

That’s it! You have now keys. Go back to “Manage root’s SSH Keys” section. There you will see that your key has been created.

You need to click on “Manage Authorization” and at the new page click “Authorize” in order to make the public key work.

Authorize key

Now you need to get the private key to your PC and keep it in a safe place. The public key will remain on the server. You can use one public key on different servers, like the lock you have on your home or your car, while your private key is the only one you can use to access the server (or open your locks).

In the same “Manage root’s SSH Keys” area, you will see the newly generated private key. Click on “View/Download key” button near the key that you have created before.

You will see two options. In case you are a Mac/Ubuntu/Other Linux user – just copy the text from the window to a file on your PC. You can name it key.ppk.

Download the key

If you are a Windows user, you will need to enter the passphrase you used while creating the key and convert the key to a format that Windows software (generally PuTTY) understands. Now copy the key in key.ppk file to your machine.

Using the key to access your server in MacOS.

1. Find the “Terminal” application in launchpad and start it.

2. Copy the key from your browser as described above.

3. Run the following command in your machine. Replace “USERNAME” with your username on your local computer:

vim /Users/USERNAME/.ssh/mykey.ppk

You will see the text editor appear. Press “shift” and “A” simultaneously.

Press “Command” and “V” simultaneously to paste the key.

Press “ESC”, then type :wq (including the colon) and press enter. This will save the key.

4. Once done here, type the following command:

chmod 700 /Users/USERNAME/.ssh/mykey.ppk

Now you are ready to connect to the server via SSH! Just run this command from the terminal window (replace USERNAME with your actual username on your local computer):

ssh -i /Users/USERNAME/.ssh/mykey.ppk root@<server’s IP address> -p<port number>

The <server’s IP address> and <port number> should be in your welcome letter (This may come as an IP address or a hostname). The system will also ask you for the passphrase.

Using the key to access your server in Windows.

1. While MacOS has an integrated terminal, you will need special software on Windows. Please download “Putty.exe.”

2. Run PuTTy. Expand the “SSH” node in the left bottom and click “Auth”. Now you need to show PuTTy the way to the downloaded private key by using the Browse button. It can have *.ppk extention or even *.txt – both will work.

ssh_6

3. Click on “Session” in the top left. Enter the “IP”, “Port” (both are in your welcome letter – this may come as an IP address or a hostname) and “Saved Sessions” (Which is a custom name for you to save this information) fields. Click on the “Save” button. You now have the session saved and don’t need to add the key again.

Connect

4. That’s it. Click “Open”, and the server will ask you for the passphrase you have used. Enter that and you will connect to the server.

We love to hear feedback and comments. Please post below to tell us what you think!

 

10 thoughts on “Setting up SSH access using keys for cPanel and WHM

    1. Guest

      Yes, I am sorry for the mistake, I have corrected this part. Command should look like:

      ssh -i /Users/USERNAME/.ssh/mykey.ppk root@ -p

      example:

      ssh -i /Users/andrew/.ssh/mykey.ppk root@127.0.0.1 -p22

      Reply
  1. Dave

    Any ideas how to do this through SSH? Cpanel and apache are down, and I need to create a key so cpanel can have access.

    Reply
    1. GlowHost.com

      Yes, you can put your key in /root/.ssh/authorized_keys2 and it should work. If you have an account with us, please open a ticket and we can do this for you as well.

      Reply
  2. Praveen Uppula

    I am trying to connect amazon aws, but getting ‘ssh_exchange_identification: read: Connection reset by peer’ error.
    Can you please help me in this.

    Reply
    1. GlowHost.com

      Are you a current customer of GlowHost? If yes, please open a support ticket so our techs can have a look. If not, it sounds like the file that has your private key is corrupt. Might want to look at that file to see if it has errors.

      Reply

Leave a Reply