Setup SSH Password less Login in Linux
Setup SSH Password less Login in Linux
SSH is a cryptographic network protocol used for secure connection between a two servers and supports various authentication mechanisms. The two most popular mechanisms are passwords based authentication and public key based authentication.In this tutorial, we will show you how to setup SSH password less login to connect to your Linux server without entering a password.
Setup SSH Password less Login
To set up a password less SSH login in Linux all you need to do is to generate a public authentication key and append it to the remote hosts ~/.ssh/authorized_keys file.
Check for existing SSH key pair:
Before generating a new SSH key pair first check if you already have an SSH key on your client machine because you don't want to overwrite your existing keys.
Run the following ls command to see if existing SSH keys are present:
ls -altr ~/.ssh/id_*.pub
If there are existing keys, you can either use those and skip the next step or backup up the old keys and generate a new one.If you see No such file or directory or no matches found it means that you do not have an SSH key and you can proceed with the next step and generate a new one.
Generate a new SSH key pair.
ssh-keygen generates, manages and converts authentication keys for ssh(1). ssh-keygen can create keys for use by SSH protocol versions 1 and 2. Protocol 1 should not be used and is only offered to support legacy devices. It suffers from a number of cryptographic weaknesses and doesn't support many of the advanced features available for protocol 2.The following command will generate a new 2048 bits SSH key pair with your email address as a comment:
ssh-keygen -t rsa -b 2048 -C "your_email@domain.com"
Press Enter to accept the default file location and file name:Enter file in which to save the key (/home/yourusername/.ssh/id_rsa):
Next, the ssh-keygen tool will ask you to type a secure passphrase. Its an option question, if you choose to use passphrase you will get an extra layer of security. In most cases, developers and system administrators use SSH without a passphrase because they are useful for fully automated processes. If you don't want to use passphrase just press Enter
Enter passphrase (empty for no passphrase):
The whole interaction looks like this:
To be sure that the SSH keys are generated you can list your new private and public keys with:
ls ~/.ssh/id_*
/home/yourusername/.ssh/id_rsa /home/yourusername/.ssh/id_rsa.pub
/home/yourusername/.ssh/id_rsa /home/yourusername/.ssh/id_rsa.pub
Copy the public key
Now that you have generated an SSH key pair, in order to be able to login to your server without a password you need to copy the public key to the server you want to manage.
The easiest way to copy your public key to your server is to use a command called ssh-copy-id. On your client machine terminal type:
ssh-copy-id remote_username@server_ip_address
You will be prompted to enter the remote_username password:remote_username@server_ip_address's password:
Once the user is authenticated, the public key will be appended to the remote user authorized_keys file and connection will be closed.
If for some reason the ssh-copy-id utility is not available on your local computer you can use the following command to copy the public key:
cat ~/.ssh/id_rsa.pub | ssh remote_username@server_ip_address "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
To know about Password-less SSH Login AIX
Login to your server using SSH keys
After completing the steps above you should be able log in to the remote server without being prompted for a password.
To test it just try to login to your server via SSH:
ssh remote_username@server_ip_address
If everything went well, you will be logged in immediately.
No comments