How To : Configure Password-less login Linux Machines

  Security, Tools

For automation and security purpose, we can configure a password-less login to Linux Machines.

1. We would need first generate a private and public key in Source Server.

Use command “ssh-keygen” and just press enter as below


root@touka:~# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:oXEDG9apwyivucwnHKZUp4HVT6L4qlY9VkQiB+con3Q root@touka.asyraf.my
The key's randomart image is:
+---[RSA 2048]----+
| oo+=o . |
| .*+.*o |
| .+o.EB.+ |
| o=++.+* o |
| o== o.S |
| .o+.+ |
|.+o+. . |
|.== . |
|+ ++ |
+----[SHA256]-----+
root@touka:~#

2. There will be 2 files created in ~/.ssh which is id_rsa and id_rsa.pub.


root@touka:~/.ssh# ll
total 20
drwx------ 2 root root 4096 Mar 2 09:27 ./
drwx------ 7 root root 4096 Feb 26 07:54 ../
-rwx------ 1 root root 401 Nov 22 10:33 authorized_keys*
-rw------- 1 root root 1675 Mar 2 09:27 id_rsa
-rw-r--r-- 1 root root 402 Mar 2 09:27 id_rsa.pub
root@touka:~/.ssh#

3. We would copy the content of id_rsa.pub to destination server to allow password-less login.


root@touka:~/.ssh# cat id_rsa.pub
ssh-rsa SINWUNJNUE+v5testKWY5idZ9BUaIjk0+ouWJXAp8RKx45KCA7+Yh27Kr07Qm9abiu+Q4e4xxMgNsCQM8RGp7bIPPQb7QYHu/wegakM0V7EM5IVGvuqt28xQ/8cmJkf+iS3enxW/fBfmzPhJmUoIp7TmE56PE7Uqbxmz/7f5KLlk9P0COEQhMcOUKz0zRrl5MROZ0tclXa+askdi1nasd81/Ghhl7gUqEK8ioWIcL4IFTepXqojClqBVx/Z+NWpFeC31eEyOSvxSWvLGYguwjfMQf7r310k+kV2H/93SAhqVu9R0BE6T9DFZo+4JA0BP root@touka.asyraf.my
root@touka:~/.ssh#

4. Copy the content to ~/.ssh/authorized_keys in Destination Server.

5. Try to login to the server.


root@touka:~/.ssh# ssh root@103.21.183.69 -p9321
Last login: Fri Mar 2 17:32:31 2018 from 45.76.148.225
[root@kaneki ~]#

As you can see, no password need to be entered.