How To Use SSH To Access Your cPanel Server

Use the SSH Access interface to securely connect to your server remotely through the command line.

This cPanel feature found at Home >> Security >> SSH Access provides information on how to connect to another web server via the SSH (secure shell) network protocol.

SSH is short for Secure Shell and it is a network protocol that allows you to connect to another web server over the Internet via a command line interface (CLI).

You can use this network protocol to remotely manage your server, configure CGI scripts, and perform other tasks.

Most modern operating systems such as Mac® OS X and Linux distributions, include SSH by default using OpenSSH.

It probably means that your local machine is already bundled with all the tools you need to access your server remotely.

If you are a Microsoft Windows user, you will need to connect to your server an SSH client such as PuTTY, KiTTY, MobaXterm, SmarTTY, or DameWare.

Connecting to a remote SSH server is as simple as just typing in the IP address or domain and port and hitting open.

If you are on Linux or Mac OS, a list of standardized Unix-based commands can be found at linuxcommand.org SSH man page, one-serve's Unix, Linux, POSIX Commands or by running the venerable man ssh command on your terminal.

Please note that not all hosting accounts qualifies for SSH access.

Even when qualifies, there is also another hoop to jump before we could enable that for your hosting account unless you are a Reseller, or a VPS or bare-metal customer.





How To Connect To Your Server Via SSH on Mac OS X or Linux

The first thing to do is to check whether you have any existing keys setup.
To do this open up your terminal and type:

cd ~/.ssh ls -al

Or just use one liner:

ls -al ~/.ssh

If there are files with names like:

id_rsa and id_rsa.pub
, it means that your computer already has a public and private key setup. If it doesn’t, you’ll need to run this command:

 

If you didn't see these, just run this command:

ssh-keygen -t rsa -C "your-email-here"
The best tutorial that will take you thorugh this can be found at Github's Connecting to GitHub with SSH.

Now repeat the

ls -al ~/.ssh

command and you shall see those files mentioned above.



To log in to your Mac OS X or Linux server via SSH, perform the following steps:

  1. Open a terminal session. You can find this wither by searching for it on Mac or visiting your Application ==> Utilities and double-clicking on "Terminal".
    For Linux, either visit Ubuntu Community Help Wiki Using The Terminal,  this YouTube video for CentOS or check your distro's documentation on that.
  2. Run the following command:
    ssh -p port user@IP
    where port represents the port number, user represents your username and IP represents your IP address.

 

To make this process faster next time you want to SSH in to this server, you can do the following after initial access.

  1. Run this command:
    ls -al ~/.ssh
    once you logged in.
  2. If there is no .ssh folder in your Home directory, you’ll need to create one.
    You can either do this manually or just follow the steps from above on generating an SSH Key to automatically have it create the folder.
    Once it is created, you’ll need to create an
    authorized_keys
    file and here’s how you can do it from the command line using these command below:
    • cd ~/.ssh
    • touch authorized_keys
  3. Now run
    ls -al ~/.ssh
    and I'm pretty sure you will see an
    authorized_keys
    file.

 

Now we gotta make sure that the permissions are setup correctly for this file and the parent folder by running these commands:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Or just do it with one-liner:
chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys

 

Now you have done that, your remote server is ready to receive a public key.
And it is pretty simple to do.
Just run the following command on your local machine:

cat ~/.ssh/id_rsa.pub | ssh user@host 'cat >> .ssh/authorized_keys'
It will ask you for a password and complete the task if you have done above correctly.
One thing to note though is that on our shared hosting servers, password authentication is disabled.

So that brings us to the next step; adding your key via cPanel and here is how to do it:

  1. Log in to cPanel and look for Home >> Security >> SSH Access.
  2. Look for Manage SSH Keys in the interface.
  3. To import an existing SSH key that you earlier generated, perform the following steps:
    1. Click Import Key
    2. To use a custom key name, enter the key name in the Choose a name for this key (defaults to id_dsa if left unnamed) text box. Do note that if you use a custom key name, you must manually specify the SSH key when you log in to the server.
    3. On your local machine, run the following command:
      cat ~/.ssh/id_rsa.pub
      . There is an alias you can use to make this faster if you have .bash_profile on your folder and it is:
      alias pb='pbcopy < ~/.ssh/id_rsa.pub'.
    4. Paste the public and private keys into the appropriate text boxes.
    5. Click Import.

 

You will have to authorize this key before you can use it for SSH access.

  1. Click on the Manage Authorization button next to the key you've just added.
  2. Click on the Authorize button.
You can now login to your server as root using this key.

 

So here are what you will essentially what you need to know about managing your keys:

The public keys and private keys tables display the following information about your existing keys:

 

ColumnDescription
Name The key's name. Public and private keys use the same key name.
Authorization Status

  Whether you authorized the key.

Please not that this column only displays in the public keys table.

Actions

You can perform the following actions:

  • Delete Key — Click to delete the key, and then click Yes to confirm that you wish to delete the key.
  • View/Download Key — Click to view or download the key. To download the key, save the contents of the Public SSH Key text box to your computer.
  • Manage — Click to manage authorization for the key. A new interface will appear. Click Authorize to authorize the key, or Deauthorize to revoke authorization for the key.

    • You can only perform this action for public keys.
    • After you deauthorize a key, that key's users cannot log in with the associated private key.



Using PuTTY

To use PuTTY to connect to your server via SSH, perform the following steps:

  1. Download and install the PuTTY client or any of those ones above.
  2. From the Windows Start menu, open the client.
  3. In the Session interface, enter the hostname or IP address of the server in the Host Name (or IP address) text box.

  4. Enter the Port number in the Port text box.

    It is advised that you ensure that you select the SSH protocol.

  5. Click Open.
  6. Enter
    root
    as the login name.
  7. Enter the
    root
    password.


To in to a server via SSH with PuTTY and a public key, perform the following steps:

  1. From the Windows Start menu, open the client.
  2. Navigate to the PuTTY Key Generator interface.
  3. Under the Actions heading, click Generate. PuTTY generates the key and displays the result under the Key menu.
  4. Copy the public key and paste it in the
    .ssh/authorized_keys
    file.
  5. Enter a passphrase in the Key passphrase and Confirm passphrase text boxes.
  6. Click Save private keyand save the key as a

    .ppk

    file.

    Note that you must save PuTTY keys as

    .ppk

    files.

  7. In the Session interface, from the Saved Sessions menu, select your preferred authorization session and click Load.
  8. Navigate to the Auth interface under the SSH category.
  9. Click Browse, select the private key file to upload, and click Open.
  10. Navigate to cPanel's Manage SSH Key interface Home >> Security >> SSH Access >> Manage SSH Keys and import the server's keys.


To in to a server via SSH with PuTTY and a public key, perform the following steps:

  1. From the Windows Start menu, open the client.
  2. Navigate to the PuTTY Key Generator interface.
  3. Under the Actions heading, click Generate. PuTTY generates the key and displays the result under the Key menu.
  4. Copy the public key and paste it in the
    .ssh/authorized_keys
    file.
  5. Enter a passphrase in the Key passphrase and Confirm passphrase text boxes.
  6. Click Save private keyand save the key as a

    .ppk

    file.

    It is important to know that you must save PuTTY keys as

    .ppk

    files.

  7. In the Session interface, from the Saved Sessions menu, select your preferred authorization session and click Load.
  8. Navigate to the Auth interface under the SSH category.
  9. Click Browse, select the private key file to upload, and click Open.
  10. Navigate to cPanel's Manage SSH Keys interface Home >> Security >> SSH Access >> Manage SSH Keys and import the server's keys.
  • ssh, cpanel
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How To Use cPanel IP Blocker To Prevent Access To An IP Address

This security feature in cPanel can be used to prevent access to your site from a range of IP...

Preventing People From Stealing Your Bandwidth In cPanel

Hotlinking to a media file (video, audio, Flash, image, etc.) on another site bypasses any html...

How To Use The Leech Protection Feature in cPanel

When your website users publicly post their username and password, malicious visitors can use...

Using cPanel Security Policy Feature

If you attempt to access your cPanel account from an unverified IP address, we require you to...

How To Enable or Disable ModSecurity on cPanel

ModSecurity is an intrusion detection and prevention engine for Apache. Known as the "Swiss Army...