Trending News
By using our website, you agree to the use of our cookies.


How to Setup SSH Keys on Linux for Passwordless Login Easy Steps
How To

How to Setup SSH Keys on Linux for Passwordless Login Easy Steps 

For remote access to Linux servers, SSH ( Secure Shell ) is widely used. When we use ssh to connect to a remote system, it asks for our password and then just allows us to connect to the server. After sshing into a remote system, we will need to customize applications or scripts (mostly shell scripts) to automate activities.

Table of Contents

SSH Keys

However, if key-based ssh is not configured, a script will prompt for a password on each run, which we must manually enter. We have an alternative to using the public/private key concept to solve this issue. On the basis of a key, the remote server allows other systems to ssh.

This guide will show you How to set up SSH Keys on Linux for Passwordless Login. In Linux systems using an ssh key pair, we can also call it password-less ssh.

Step 1: Generate an SSH key pair

To begin, you will need to generate a key pair (RSA or DSA), which you can do by using the ‘-t’ command line switch to specify the option rsa or dsa key. If the -t parameter is omitted, an rsa key will be produced by default.

					ssh-keygen -t rsa

					Generating public/private rsa key pair.
Enter file in which to save the key (/home/yehiweb/.ssh/id_rsa):
Created directory '/home/yehiweb/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/yehiweb/.ssh/id_rsa.
Your public key has been saved in /home/yehiweb/.ssh/
The key fingerprint is:
SHA256:GZQ3tJffEUimdMZHIG3LcpvdkOaogwXBtWeaM2ejzYY yehiweb@example
The key's randomart image is:
+---[RSA 2048]----+
|       ..+oo+*+o |
|       .+ +o** ..|
|        .oooB oo |
|        .o B =+..|
|        S.= *+=.o|
|          .X.+...|
|         oE.+    |
|        . o.     |
|           .     |

The above command will generate the following two files in the /.ssh directory.
  1. ~/.ssh/id_rsa [private key]
  2. ~/.ssh/ [public key]

Step 2: Copy the Public Key to the Remote System

Let us copy our system’s public key to the /.ssh/authorized keys key file on remote systems. This can be done manually or with the help of the ssh-copy-id command-line tool. ssh-copy-id -i ~/.ssh/ Output Example:

					ssh-copy-id -i ~/.ssh/
root@'s password:
Now try logging into the machine, with "ssh ''", and check in:


to make sure we haven't added extra keys that you weren't expecting.


It will ask you for the remote system’s password. Type the password for the remote machine and press Enter.

Step 3 – SSH without Password Verification

Now, as we have done before, try sshing into the remote system. You can access the remote system without having to type a password.

					ssh root@

The password would not be used to log in with the command above. In any case, if the ssh command asks for a password, the setup is not configured properly, and you can repeat all of the steps.

Final Thoughts

You learned how to generate an SSH key pair and set up key-based authentication between two systems in this tutorial. It is a password-less login for Linux systems.

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on reddit
Share on vk
Share on tumblr
Share on skype
Share on stumbleupon
Share on whatsapp
Share on email

Related posts

Leave a Reply