Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Network Services»SSH»How to Set Up Key-based SSH Login in Linux

    How to Set Up Key-based SSH Login in Linux

    By RahulJuly 18, 20213 Mins Read

    In the early 90s, IT professionals were using Telnet for data transfer which was an application layer protocol and used to transfer data without encryption. Later a secured alternative of Telnet SSH was created which encrypts the data so that others cannot retrieve it without access.

    Advertisement

    SSH or Secure Socket Shell is a network protocol used to access a system or server remotely in a secured way. It is an application layer protocol and it enables you to access another machine without physical access remotely via the internet. With SSH you can issue remote commands, transfer files, connect to remote servers, and can communicate between two computers in an encrypted way.

    You can log in to your remote SSH server by types:

    • Password Authentication
    • Public Key Authentication (Passwordless)

    Here we will discuss configuring key-based authentication for SSH login.

    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 the -t parameter, it will default create a RSA key.

    ssh-keygen -t rsa 
    

    Follow the quick wizard:

    1. Enter and accept the default location. You can also select a different filename and location.
    2. Next, you will be asked for a passphrase. It depends on you that if you want it or not. If you do not want it then press Enter otherwise enter a passphrase for an extra layer of security. Also, not using a passphrase will help you in automating a lot of tasks.
    3. Hit Enter and your keys will be created.

    Now, you can see the generated key files with the following command.

    ls -l .ssh/ 
    

    Step 2 – Copy Public Key to Remote System

    the ~/.ssh/authorized_key is the file responsible for keeping public keys of remote clients. During the key-based authentication, the system checks for the public keys in the same file.

    You can simply copy the content of public-key (file with .pub extension) from your system to the authorized_key file on the remote server. Otherwise, let it be done by running the following command.

    ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.10.20 
    
    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.

    You will be asked for the remote_user password. Once you enter the correct password, the public key will be stored in the remote server.

    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] 
    

    You should log in automatically now, without prompting for the password. If in case, the system is prompted for the password, means the key is not correctly copied on the destination server. To resolve this, check the key is properly appended to the authorized_key file and its permissions.

    Conclusion

    In this tutorial, you have learned to create SSH key pair and configure key-based login between two systems.

    dsa login password rsa secure shell SSH
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How To Display Warning Message to Unauthorized SSH Access

    How to Set a Custom SSH Login Banner and MOTD

    How to Install and Secure OpenSSH Server on Pop!_OS

    View 4 Comments

    4 Comments

    1. Robert T. Clark on February 9, 2014 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.

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

      Great post.

      Reply
    3. Sherry B. McWilliams on January 16, 2014 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.

      Reply
    4. Tracy P. Hall on January 14, 2014 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.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • tail Command in Linux with Examples
    • What is a Orphan Process in Unix/Linux
    • How To Display Warning Message to Unauthorized SSH Access
    • How to Set a Custom SSH Login Banner and MOTD
    • Understanding Reverse DNS: What it is and Why it Matters?
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.