Logging on to shared hosting with SSH

Logging on to shared hosting with SSH

Secure Shell (SSH) is a way to securely access a container or a server. The connection is encrypted using a private key and a public key. You will hold the private key on your local computer while having the public key on the remote server. This way, no one but someone with the private key can access the remote server. And as long as you keep your private key for yourself, no one but you is granted access.

In this blog post we will get our SSH credentials from one.com. We will then get onto generate a key-value pair. In the case of one.com there is no client-accessible ssh agent installed, but there is still a way forward where we won't be prompted for our password each time. We will find out how!

Note that we will be using either example or satius for inputs. You can switch these out for your domain name.

Get SSH credentials

This is specifically for one.com, but the process of getting an SSH inlog may be similar with your hosting service.

How to get SSH username and password in 5 steps
Step 1
Log in to your account and select the domain you want to add an SSH to.

Step 2
Select the item 'SSH & FTP' under 'Advanced Settings'.
Advanced Settings.png 23.86 KB


Step 3
Activate 'Allow SSH & SFTP access' and click 'SEND'. Take note of host (ssh.example.com) and username (example.com)
SSH Administration.png 58.16 KB



Step 4
You should have received an email from one.com to the address you registered with them. Look for an email titled 'Change SSH/SFTP password' or similar. The email will contain a link ro reset password, click it.
One Mail.png 68.46 KB


Step 5
Make a secure password and retype it. After this step you will have the password and username you need to log onto your webspace.
Change Password.png 44.1 KB

Logging in with username and password
You can now log on with SSH using Git Bash. This is the way to do it:
ssh example.com@ssh.example.com
This will prompt for your password. No output will show as you are entering your password, so don't be too thrown off by it. When you've entered the correct password you will be granted access!
ssh-p-u.gif 1.15 MB


Logging in with SSH key

Sometimes it can be tedious to rely on entering host address, username and password. And when you are using deploy tools it can be entirely cumbersome. So let's set up a public and private key to help us along. We will continue to be using Git Bash for Windows in this section.

Generating public and private keys
We have access to the tool <em>ssh-keygen</em> in Git Bash. We will be using it, but before we do. Let's navigate to ~/.ssh. This is the .ssh-directory in your home catalog. If you don't have this directory you can create it with mkdir ~/.ssh

In the directory ~/.ssh, run ssh-keygen. This will start the key-generation. It will prompt you for  a name for the keys. Either enter one or accept the default (id_rsa). Then it will prompt you for a passphrase if you would like to add one to the keys. If not, it's just as simple as pressing enter twice.
Generate Keys.png 267.51 KB


If you check what's in the directory now, you will see that two files were added. One private key (default id_rsa) and one public key (default id_rsa.pub).

Next we are going to add the public key (id_rsa.pub) to the remote server. First we will copy the contents of the key. Run cat id_rsa.pub. Copy the text string. In Git Bash for Windows you can do this by pressing ctrl+ins
Copy Contents.png 181.01 KB


Let's login to the remote server: 
ssh example.com@ssh.example.com
You will be prompted for your password, so enter it. Remember that no output will be generated as you type. Upon correct password you will be logged on.
We will now create a way to access this webspace with the key we generated. First we create a directory: 
mkdir ~/.ssh
This is a hidden directory, so it will only show up when you run ls - a 
Move into this newly created directory: 
cd .ssh
Now we will create a file to store the public key we generated:  
touch authorized_keys
Open the file with a text editor. Nano is quite simple:
nano authorized_keys
Paste the contents of the public key into the file by pressing shift+ins, provided you did copy the public key into your clipboard. Press ctrl+x to exit Nano. It will prompt you for saving a buffer, press y and then press enter again to save it with the same filename (authorized_keys).
You can exit the connection to the remote server by typing exit.

Next up you are going to configure a SSH connection to the remote server so we don't have to type credentials each time. Create a config file by running the following command: touch ~/.ssh/config
Then let's add some info into the config file. Open it with nano ~/.ssh/config and type in the following:
Host example
    HostName ssh.example.com
    User example.com
    IdentityFile /c/Users/example/.ssh/id_rsa

Exit the editor by pressing ctrl+x. Save the buffer when prompted to the same filename as before (config).

ssh config.png 198.65 KB

It's now as easy as running ssh example to logon. Or in my case it would be ssh satius.