• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

RSA key authentication in Linux : Passwordless login

November 28, 2011 by Sharad Chhetri Leave a Comment

RSA key authentication in Linux : Passwordless login

Scenario :

(1) Two Servers

Hostname : Server1 , username : test (user must exist in server)
Hostname : Server2 , username : test  (user must exist in server)

(2) We want to login into Server2 from Server1 without giving passwd.
means when we do “ssh test@server2” it should not ask passwd.

How to :

(a) Login into server1 by user test.

use the command: ssh-keygen -t rsa

And just hit enter enter enter , donot give any passphrase passwd.

[test@server1 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/test/.ssh/id_rsa):
Created directory ‘/home/test/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/test/.ssh/id_rsa.
Your public key has been saved in /home/test/.ssh/id_rsa.pub.
The key fingerprint is:
49:a4:1e:b8:df:13:36:fa:25:5a:d3:d2:f5:9e:77:98 test@server1
[test@server1 ~]$

Two files id_rsa and id_rsa.pub would be created in /home/test/.ssh directory

[test@server1 ~]$ ls -lrt .ssh/
total 8
-rw-r–r– 1 test test  410 Nov 27 23:06 id_rsa.pub
-rw——- 1 test test 1671 Nov 27 23:06 id_rsa
[test@server1 ~]$

(b)  now scp the id_rsa.pub file into server2
[test@server1 ]$ cd /home/test/.ssh
[test@server1 .ssh]$ ls -lrt
total 8
-rw-r–r– 1 test test  410 Nov 27 23:06 id_rsa.pub
-rw——- 1 test test 1671 Nov 27 23:06 id_rsa
[test@server1 .ssh]$
[test@server1 .ssh]$ scp id_rsa.pub test@server2:~

(c) Now login into Server2 by user test:

Check if /home/test/.ssh directory exist or not.

ls -ld /home/test/.ssh

if the .ssh directory does not exist make a new directory.

[ test@server2 }$mkdir -p /home/test/.ssh

Now change to directory .ssh

cd /home/test/.ssh

Create one file inside .ssh called  authorized_keys

[test@server2 .ssh]$ pwd
/home/test/.ssh
[test@server1 .ssh]$ touch  authorized_keys
[test@server2 .ssh]$ ls
authorized_keys

(d) now copy the content of id_rsa.pub which u scp from server1 into the file /home/test/.ssh/authorized_keys

[test@server2 .ssh]$
[test@server2.ssh]$ cd ~
[test@server2 ~]$
[test@server2 ~]$ cat id_rsa.pub >> /home/test/.ssh/authorized_keys

(e) Check the permission and ownership of .ssh directory and authorized_keys file. It must be like below information

[test@server1 ~]$ ls -ld .ssh/
drw-r-xr-x 2 test test 4096 Nov 27 22:56 .ssh/
[test@server1 ~]$
[test@server1 ~]$ ls -lrt .ssh/
total 4
-rw-r–r– 1 test test 412 Nov 27 22:55 authorized_keys
[test@server1 ~]$
[test@server1 ~]$

Note in Server2 : you should login with root user here

check sshd configuration:
vi   /etc/ssh/sshd_config  (on the Linux box)
RSAAuthentication   yes
PubkeyAuthentication  yes

/etc/init.d/sshd reload
or
/etc/init.d/sshd restart

Now logout from Server2 and try to ssh from Server1 to Server2,it should not ask passwd for login.

[test@server1 ~]$  ssh test@server2

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. lock user login after failed login attempts in Red Hat 6.x and CentOS 6.x
  2. Agent admitted failure to sign using the key ssh
  3. How To Get SSH Public Key Fingerprint Information
  4. In ESX , passwd: authentication information cannot be recovered
  5. How to configure vsftpd server with virtual user mysql authentication in CentOS 6
  6. Setup CRAM-MD5 authentication for mailing in owncloud Ubuntu
  7. Postfix + SES : SASL authentication failed
  8. error: Could not load host key
  9. sshd error could not load host key
  10. Create bootable usb key for CentOS 7 installation

Filed Under: Linux, SSH Tagged With: Passwordless login, ssh

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

SSH WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED

fatal error: error writing to /tmp/ccwAjc9Z.s: No space left on device

How to download package using apt-get command in ubuntu

How to empty Trash through command line in Ubuntu

Run the script using nohup without hitting enter key two times

Install and optimize the png file by using optipng

How to use grep command to get fixed pattern or exact keyword

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ·
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy