How to add ssh key to Hostinger – Shared Hosting

Steps on creating, copying SSH Key

In this tutorial we will learn how to set up SSH key on our local device and use the generated pair of keys for connecting to a remote server.

For demonstration we will be using hostinger Hostinger Servers

This method is more convenient, flexible and provides a more secure way of connecting to the remote server/machine than simply using a password.

What you’ll need

Before you begin this guide you’ll need the following:

  • Local device.
  • Access to the remote device.
  • A terminal suitable for SSH connection.

Step 1 — Generating the SSH key

We will be generating RSA keysand set up the RSA keys on Linux / Unix system using  Terminal of environment which your local device has.

After entering the Terminal, you will be taken to a window similar to this:

Tesmachino Ubuntu terminal

Note: I am using Ubuntu, Putty in windows will look different

Here you can start writing needed commands:

The first thing you need to do is generate the pair of keys on your local machine. You can do it with this simple command:

ssh-keygen -t rsa

Once you enter this command, a few new questions will pop up:

Enter file in which to save the key (/home/tesmachino/.ssh/id_rsa):

Generally it is recommended to simply leave it as it is (press ENTER without typing anything) so that the key generator could create the key pair in the default location (in this tutorial I entered a different name testing to avoid duplicate keys, since my local device already had an id_rsa keys generated).

Second two questions which will pop up:

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Now for convenience reasons, I like to leave those empty as well. That way, after setting the keys up with your remote server, you won’t need to use any kind of password to log in. You will simply enter the ssh user@serverip command and it will log you in as long as the keys are properly set up. But if you need even more security, you can enter a passphrase in this section. If you choose this option, you will need to enter the password every time you connect to the remote device.

That is basically it, you should see something like this in your Terminal:

tesmachino ssh-keygen -t rsa ubuntu terminal
ssh-keygen -t rsa creates RSA public and private key

Note: Your terminal will look different from mine. As well as the key fingerprint.

There are two keys created here (PRIVATE and PUBLIC): testing and testing.pub (if you didn’t changed default, your case, should be id_rsa and id_rsa.pub). Please make sure that that id_rsa which is private key should not be shared to anyone. Keep it confidential.

Ubuntu terminal change directory
Changing to .ssh directory. ~/ denotes `Home’ directory of current user in Linux

Note: Please beware of the permissions. Permissions should not be too open.
Only testing.pub should be uploaded to remote servers.

Step 2 — Copying the Public key to your remote server

After generating the RSA key pair, we have to put our public key to the remote virtual server.

Navigate to Hostinger SSH

copy text terminal cat command - tesmachino terminal
Copy the text from the testing.pub

Navigate to SSH section in your Hpanel in Hostinger,

In your Terminal open the testing.pub

Hostinger login page - hpanel for tesmachino
Hostinger Login page

Choose Your Account > Click Manage > Advanced > SSH

selecting ssh option from hostinger ssh - tesmachino - enable ssh

By Default SSH is turned off. Please turn on the ssh.

Paste the copied testing.pub key to the block and submit. !!! Voila.

adding ssh key to the cpanel shared hosting - hostinger - tesmachino

You can now login directly to server using the ssh key installed just now.

enabling ssh access shared hosting - hostinger - temsachino

Back to local Machine

Copy the SSH Command {ssh -p 65002 user@serverip} and proceed to terminal. Paste the Command,

After entering the command in terminal, you should be greeted with a Warning message similar to this:

The authenticity of host 'Server's IP address' can't be established.

RSA key fingerprint is ...

Are you sure you want to continue connecting (yes/no)?

After Submitting you will be taken to shell. You are now logged in as user.

If your collegue would like to access the shell they could follow the same steps or they could email you the public key so that you could add it by yourself isolating the hpanel from them :)

STEP -2

There is a simple command which will put your public key directly to the remote server’s authorized_keys file (this file keeps all the public keys:

ssh-copy-id user@serverip

Type in yes in the command line and hit ENTER. This message appears only the first time you are performing this action.

Another message will pop up:

Password -Create new FTP account since hostinger shares FTP and ssh account credentials.

Warning: Permanently added 'SERVER IP' (RSA) to the list of known hosts.

user@serverip's password:

Here you must enter the password of remote server user (in most cases username is user part of the ssh command). After entering the password, that should basically be it. You will be greeted with another message:

Now try logging into the machine, with "ssh 'user@serverip'", and check in:

~/.ssh/authorized_keys*

to make sure we haven't added extra keys that you weren't expecting.

as the new public key has been added to your remote server. Now every time you log into your remote server, you won’t be prompted for a password (unless you set up a passphrase for your RSA key in the generation process).

Thank you for your patience. You have learned 2 methods on adding ssh key to shared hosting server