• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Setup SSH Keys for Passwordless Login on Linux

Written by Rahul, Updated on May 21, 2020

SSH ( Secure Shell ) is widely used for remote login to Linux servers. When we log into a remote system using ssh, it prompts for the password and then only allow us to login to the server. Sometimes we need to configure applications or scripts (mostly shell script) to automate tasks to do after ssh to the remote system. But if we do not have configured key-based ssh, a script will prompt for password on each run which we need to manually enter. To solve this problem, we have an alternative to using public/private key concept. In which remote server allows other systems to ssh on basis of key.

This article will help you to Setup SSH Keys on Linux system. We can also say it password-less ssh in Linux Systems using an ssh key pair.

Step 1 – Generate SSH Key Pair

Firstly you would require generating a key pair (RSA or DSA), you can specify option rsa or dsa key using ‘-t’ command line switch. If we do not pass -t parameter, it will create rsa key by default.

ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/rahul/.ssh/id_rsa):
Created directory '/home/rahul/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/rahul/.ssh/id_rsa.
Your public key has been saved in /home/rahul/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:GZQ3tJffEUimdMZHIG3LcpvdkOaogwXBtWeaM2ejzYY [email protected]
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 create two files in the ~/.ssh directory as followings.

  1. ~/.ssh/id_rsa [private key]
  2. ~/.ssh/id_rsa.pub [public key]

Step 2 – Copy Public Key to Remote System

Lets copy our public key of our system to remote systems ~/.ssh/authorized_keys key file. We can do this manually or using ssh-copy-id command line tool.

ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.10.20

Sample Output:

21
[email protected]'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 prompt for the password of the remote system. Enter remote machine password and press enter.

Step 3 – Verify SSH without Password

Now as we have all done, simply try to ssh to the remote system. You will log in to the remote system without entering the password.

ssh [email protected]

Above command will not prompt for the password to log in. In any case, if ssh command prompts for the password, it means your setup is not configured properly and try again all the steps again.

Conclusion

In this tutorial, you have learned to create SSH key pair and configure key-based login between two systems. You can say it password-less login for Linux system.

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

4 Comments

  1. Avatar Robert T. Clark Reply
    February 9, 2014 at 9:51 am

    I have been browsing online more than 3 hours today, yet I never found any
    interesting article like yours. It’s pretty worth enough for me.

    In my view, if all website owners and bloggers
    made good content as you did, the web will be much more useful
    than ever before.

  2. Avatar Tracy S. Prather Reply
    January 20, 2014 at 4:41 pm

    Great post.

  3. Avatar Sherry B. McWilliams Reply
    January 16, 2014 at 11:35 pm

    Great post. I was checking constantly this
    blog and I’m impressed! Extremely helpful information specially the last part 🙂 I care for such information much.
    I was looking for this certain info for a long
    time. Thank you and good luck.

  4. Avatar Tracy P. Hall Reply
    January 14, 2014 at 3:51 pm

    Excellent post. I was checking continuously this blog and I am impressed!
    Very useful info specially the last part 🙂 I care for such info much.
    I was seeking this particular information for
    a long time. Thank you and good luck.

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
  • How To Install NVM on macOS with Homebrew 0
  • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
  • How to Install .NET Core on Debian 10 0
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy