How to setup passwordless SSH Authentication in Linux ?

On Local Machine, from where you will try to login another machine, we need to use ssh-keygen to create ssh public/private keys. ssh-keygen generates, manages and converts authentication keys for ssh.

$ ssh-keygen 

Generating public/private rsa key pair.
Enter file in which to save the key (/home/devbee/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/devbee/.ssh/id_rsa.
Your public key has been saved in /home/devbee/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:oq5Hd9kjiJibI5tI9RvsM4InJ7nyRzeVR3nTjDY5kL8 devbee@laptop
The key’s randomart image is:
+—[RSA 2048]—-+
| .+ = |
| + O o |
| o + + |
| o . . |
| + ..oS+ . |
| + *.=.+ o E |
| .o=.* o . . |
|=*+=+oo |
|==O=ooo |
+—-[SHA256]—–+

This will create public and private ssh keys at your /home/myuser/.ssh directory.

$ ls -l /home/devbee/.ssh/
total 12
-rw------- 1 devbee devbee 1679 Aug 24 09:13 id_rsa
-rw-r--r-- 1 devbee devbee 395 Aug 24 09:13 id_rsa.pub
-rw-r--r-- 1 devbee devbee 442 Jan 31 2018 known_hosts

Copy the contents of ssh public key as, ( copy output of below command )

$ cat /home/myuser/.ssh/id_rsa.pub

and then first using your username and password, login to remote machine as,

$ ssh remote_username@remote_machine_ip 

[ Note: for adding key to remote machine, if you do not have access, you can send the key to your admin and ask them to append ]
Now, on remote machine, you need to append the copied ssh id_rsa.pub public key to authorized_keys as,

 $ vim /home/remote_user/.ssh/authorized_keys 

Append copied key, save and exit.

Related :   How to Scan for mDNS/DNS-SD services published on the local network using mdns-scan command ?

Now, exit from remote machine, and try login to remote machine from localmachine as,

 $ ssh remote_user@remote_ip_address 

This should login without asking any password. ( Since we have already authenticated using ssh public key )


lynxbee_ezoic

Subscribe with Valid Email Id to receive updates in Inbox. ( Secured by Google FeedBurner )

   


Leave a Comment

Android Android Applications Android Build system Android Commands Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development & Build Development, Debugging and Performance Tools Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web design and development Website Hosting Wordpress Yocto / Bitbake / Openembedded