• mehdi@mkvlab.at

SSH to Linux Server Without Password!

The SSH public-private key pair allows you to securely log into AST’s servers and perform authentication without having to specify a password using the public key. It also allows you to send files via an encrypted network connection. You can add as many key pairs as you like. All pairs are independent, and each computer only has information regarding its pair. You can easily transfer your client machine’s public RSA key to your Linux box, and then the world will be nicer for you.

Generate Public/Private Key

First of all, we need to generate our client’s public key. Then we can transfer the key to the Linux server to define it as an authorized SSH key. I will generate them on 3 different machines: Windows 10, macOS Sierra, and Debian Linux.

On Windows client:

On Windows, we need to use a program called Git to generate the key. You can download Git from this page. Also, you can use PuTTYgen to generate your Windows client key.  PuTTYgen is included in the WinSCP installation package that you can download from WinSCP download page.

After installing Git, you need to execute Git GUI from the Git folder in the start menu. To generate a key, just open the Help menu and select Show SSH Key.

By pressing Generate Key and then setting up the passphrase (recommended to set a passphrase) you can see and copy your public key to your clipboard or copy to Notepad to use it in the next step.

On Mac client:

Here, generating the key is much more convenient, you need to open the Terminal and run the following commands.

ssh-keygen –t rsa
4

Your key is now saved in id_rsa file under .ssh directory, which you can access with the command:

cd .ssh
ls

And you can copy to the clipboard with the command:

pbcopy < ~/.ssh/id_rsa.pub

On Linux client:

On a Linux box, generating the key is quite similar to Mac. Need to run the same command in your terminal of choice.

ssh-keygen –t rsa
4

Your key is generated and saved in .ssh directory under your home directory. You can access it with the following command, and also copy the key.

cd $HOME/.ssh/
ls
cat id_rsa.pub

Transfer your client’s public key to the Linux box

Now you need to transfer the key to the Linux server and make it an authorized SSH client. You can verify the keys that you have already added by the command:

cat /root/.ssh/authorized_keys
5

You can edit this file with your editor of choice, like nano, and add your client public key for instance, in Linux and Mac use the following command to transfer your key easily to the server.

ssh-copy-id root@<Server IP>
6

You are done and good to go! Successfully transferred the client key to the server, and now we can connect to the Linux server without a password required, and most importantly, SECURE.

7
Tags :

Leave a Reply

Your email address will not be published. Required fields are marked *