SSH stands for
Secure Shell or also known as
Secure Socket Shell. SSH allows us to access a remote computer/server in a secure way over an insecure network such as the internet.
It provides authentication and an encrypted communication between two computers.
You can use Command Prompt (CMD) or Git Bash. Download
Git Bash from here.
Windows(older version) Users
If you are using an
older version than Windows 10 then you should use an open source SSH client called
You can download PuTTY from here for Windows.
You can use their terminal which comes pre-installed.
For authentication there are two common ways:
Authenticating using a Password is less secure and is generally not recommended way to access your server.
You need to type the following command in your terminal such as
git bash if using Windows:
usernameis the username of any user on the server. Generally the username is
rooton most systems
ipaddress is the IP address of the server
Once you execute this command, it will prompt you for the user's password.
That's it! You can then access your server, create files and folders, install programs etc.
Using Public/Private Key Pair for authentication is a more robust and secure way of authentication.
There are two ways for generating public/private keys and connecting to the server via SSH
For generating public/private key and connecting to the server via SSH we will use an open source SSH client called Putty on Windows.
You can download PuTTY from here for Windows.
Once it is downloaded install the program.
PuTTYgen - PuTTY Key Generator and open it.
Click on Generate
Move your mouse randomly within the box to generate a random key
Once keys are generated, provide a
key passphrase (recommended) for further security
Save both the private and public key to any secure location you wish
Also copy the public key that is shown in the box as we will need it later
Now we need to store the public key on the server so that we can connect to the server as we already have the private key with us.
Paste the public key into the
authorized_keys file on the root of the server.
Generally your server provider will provide you some easy user interface to paste the public key eg. In Digital Ocean you can go to Account section in the navigation menu then select Security. Under the SSH keys section simply click Add SSH Key and paste your public key.
Note: Public key should be in one line format, key starts with ssh-rsa
Now that everything is ready, we will connect to the server:
SSH in the side menu, then click
Now browse your private key by clicking Browse button and after selecting your private key click open
Session in the side menu. Provide the
hostname/IP address of your server
As you are connecting to the server for the first time, PuTTY will prompt you to ask "if you trust this server". Click yes to save it in PuTTY's cache or No to continue without saving the identity of server.
Enter your server's username eg. root
Enter the passphrase if you had provided it during generation of keys
That's it! If you have followed all the steps correctly then you should be able access your server
We will see how we can generate keys and upload public key to the server and finally connect to our server using SSH.
To generate the ssh public/private keys, Open your terminal and execute the following command:
Enter the location where you want to save the keys and also provide name for the files. You can leave it blank and just click enter, it will save bothe keys in
/.ssh/ with names Private key -
id_rsa and Public key -
You can also enter a
key passphrase (recommended)
This will generate the public/private keys in the specified location
We now need to upload the public key to the server. Public key must be in
authorized_keys file which should be in
The following command will copy the public key from
/.ssh/id_rsa.pub and paste it on the server at the location -
cat ~/.ssh/id_rsa.pub | ssh email@example.com.*.* "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys"
In the above command, specify the correct path and name of your public key eg.
~/.ssh/id_rsa.pub, specify the username for the server's user and also specify the IP address of your server
Once you execute the following command, you would be asked -
"Are you sure you want to continue connecting (yes/no)?", type
yes and then you would be asked for the
passphrase (if provided).
That's it. You will be able to access your server directly from your terminal with SSH as follows:
If you had provided the passphrase, it would ask for it.
That's it! You will be connected to your server and can create files and folders, install programs etc
From this post we learned:
I hope this post was useful for you and you learned something out of this post.