The SSH protocol uses encryption to secure the connection between a client and a server. All user authentication, commands, output, and file transfers are encrypted to protect against attacks in the network.
Let’s say you want to setup a cron job to copy some files to another server, like backup files. By far the most secure way is to login to the remote server with your public key.
Generate an RSA key pair by typing the following at a shell prompt:
ssh-keygen -t rsa
Generating public/private rsa key pair. Enter file in which to save the key (/home/alex/.ssh/id_rsa):
Press Enter to confirm the default location (that is,
~/.ssh/id_rsa) for the newly created key.
Enter a passphrase, and confirm it by entering it again when prompted to do so. For security reasons, avoid using the same password as you use to log in to your account.After this, you will be presented with a message similar to this:
Your identification has been saved in /home/alex/.ssh/id_rsa.
Your public key has been saved in /home/alex/.ssh/id_rsa.pub.
The key fingerprint is:
The key's randomart image is:
+--[ RSA 2048]----+
| E. |
| . . |
| o . |
| . .|
| S . . |
| + o o ..|
| * * +oo|
| O +..=|
| o* o.|
Change the permissions of the
chmod 700 ~/.ssh
Now to push your key to the remote machine you want to ssh into type the following command:
That’s all! Now just try to ssh into the host. You will no be prompted for a password:
Working in IT for more than 10 years now, I’ve run into problems that are very specific to network and system administration.