SSH packets being sent from the SSH client to the server are encrypted with a form of shared-key cryptography, using a random key which is generated for each new connection and thrown away when that connection is over. The client and the server use public-key cryptography to agree on the session key, and either party may request a re-keying of the session at any time.

Once you become familiar with SSH keys, communication and file copying between servers/clients will be secure, quicker, and more convenient.

Here’s an example of setting it up between a CentOS Client and a CentOS Server:

On the client, do the following:

  • Go to the .ssh directory, which is located under /root – the full path is /root/.ssh
  • Now let’s create our private and public keys and put them into a file.

This created a 1024-bit key and created 2 files.

 

  1. id_dsa_something – This holds your client’s PRIVATE Key.
  2. id_dsa_something.pub – This holds your server’s PUBLIC key.

Let’s place the key id_dsa_something.pub into the server's authorized_keys file. Located at: /root/.ssh/authorized_keys, if this file is not already there, we will create it.

Next, you need to copy the key to your system. We’ll copy the key over via a file-copying program called rsync

Make sure to change SERVERSIP to the server's IP address. After doing this command, you will be prompted for the root password of the server, type it, and press enter.

Now, on the server, do the following:

The 2nd command copies the contents of id_dsa_something.pub into the authorized_keys file. The 3rd command gives it the correct permissions to be run by the system.

Now, back to the client, do the following:

2nd command: Starts the SSH agent program.

3rd and 4th command: Adds your private key into memory.

Simply SSH into the server.

When prompted, type in the root password. Now exit out and try to SSH into the server from the client once more. This time – you shouldn’t be prompted for a password.

Was this answer helpful? 0 Users Found This Useful (0 Votes)