Secure Communication using SSH

This time I was checking out OpenSSH. It is a network protocol which uses asymmetric key cryptography to provide secure data communication over an unsecured network. There is also a network protocol for “file transfer” SCP(Secure Copy) based on SSH. It uses SSH for data transfer and authentication ensuring authenticity and confidentiality of data.
In this post, I would like to explain how to connect to a remote system using SSH, transfer files securely and how to get password less access to a remote server.

Installing and Connecting to a remote server

I most Linux distros are shipped with only SSH-Client installed. If you would like to copy files  from your system from a remote system, you will have to install SSH-Server. If not, SSH-Client will be just fine.
To install SSH-Server, you can use the following command.

sudo apt-get install openssh-server

To connect to a remote server, the following command should work fine.

ssh <user>@<server IP/URL>

The above command will prompt for a password for the specific user at the server. Once you enter the correct password, you will get access to the shell of that user in the remote server. Now you can do whatever operations you like on the remote server, under the privilege of the user.

Copy using SCP

As you have seen, you can get access to a remote system using SSH. But SSH does not support file transfer. For that purpose, we use SCP. The command for transffering file from/to a remote server is as follows.

  • To copy a file to a remote host.
    scp <local file path> <usre>@<remote host IP/URL>:<remote location>
  • To copy a file from a remote host
    scp <user>@<remote host IP/URL>:<remote location> <local location>

Password less entry to an SSH Server

For enabling our system at achieve password less entry to a remote server using SSH, we use a public-private key pair. So first we have to generate a key pair. The following command helps you in creating a key pair


Here I am using RSA algorithm to generate my key pair. ssh-keygen command supports DSA & ECDSA. It will ask you for the passphrase(private key) and then generate the public key file.

Now we have to copy this public key to the remote host. For that we use the following command.

ssh-copy-id -i <public key filename> <user>@<remote host IP>

This will copy your key file to ~/.ssh/authorized_keys on the remote server.Now when you try to connect to the remote host using SSH, it will ask for the password only for the first time. njoy….


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s