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
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
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/id_rsa.pub. 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. | | . | +----[SHA256]-----+ The above command will generate the following two files in the /.ssh directory.
- ~/.ssh/id_rsa [private key]
- ~/.ssh/id_rsa.pub [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/id_rsa.pub 192.168.10.20 Output Example:
ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.10.20
21 firstname.lastname@example.org's password: Now try logging into the machine, with "ssh '192.168.10.20'", and check in: .ssh/authorized_keys 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.
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.
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.
How to use Registry Editor to navigate to any Registry key with a single click
You might get tired of manually navigating to various registry keys if you find yourself fiddling with Registry Editor and…