How to login another machine without password OR How to setup passwordless SSH login 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 [email protected]
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 [email protected]_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.

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

 $ ssh [email protected]_ip_address 

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

Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home HTML JAVA Programs Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply