Contents
How to connect in SSH without password
The SSH protocol allows you to connect to a remote machine securely using asymmetric cryptography. SSH is widely used by system administrators because it is simple to set up and very powerful.
However, by default, you must use a password to authenticate on a remote computer with SSH. It is not very restrictive if you have a single server, but if you have several machines with the need to script to automate certain tasks, it becomes complicated for 2 reasons. The first is that it is not easy to “script” an SSH connection with a password. The second is that it is not at all secure since the password is hard coded.
In this tutorial, we will see how to set up a public key / private key system to connect without password securely.
In this article, we will show you How to connect in SSH without password
My Setup Environment
1 2 |
SSH Client : 192.168.1.10 ( Fedora 21 ) user: devopsclient SSH Remote Host : 192.168.1.11 ( CentOS 7 ) user: devopsserver |
In this example, we will set up SSH password-less automatic login from server 192.168.1.10 as user devopsclient to 192.168.1.11 with user devopsserver.
Step 1: Create Authentication SSH-Keygen Keys on
First login into server 192.168.1.10 with user devopsclient and generate a pair of public keys using the following command.
1 |
[devopsclient@devops-team ~]$ ssh-keygen -t rsa |
Step 2: Create .ssh Directory on (server) – 192.168.1.11
Use SSH from server 192.168.1.10 to connect server 192.168.1.11 using devopsserver as a user and create .ssh directory under it, using the following command.
1 |
[devopsclient@devops-team ~]$ ssh devopsserver@192.168.1.11 mkdir -p .ssh |
Step 3: Upload Generated Public Keys to (server) – 192.168.1.11
Use SSH from server 192.168.1.10 and upload a new generated public key (id_rsa.pub) on server 192.168.1.11 under devopsserver‘s .ssh directory as a file name authorized_keys.
1 2 3 |
[devopsclient@devops-team ~]$ cat .ssh/id_rsa.pub | ssh devopsserver@192.168.1.11 'cat >> .ssh/authorized_keys' devopsserver@192.168.1.11's password: [Enter Your Password Here] |
Step 4: Set Permissions on – 192.168.1.11
Due to different SSH versions on servers, we need to set permissions on .ssh directory and authorized_keys file.
1 2 3 |
[devopsclient@devops-team ~]$ ssh devopsserver@192.168.1.11 "chmod 700 .ssh; chmod 640 .ssh/authorized_keys" devopsserver@192.168.1.11's password: [Enter Your Password Here] |
Step 5: Login from 192.168.1.10 to 192.168.1.11 Server without Password
From now onwards you can log into 192.168.1.11 as devopsserveruser from server 192.168.1.10 as devopsclient user without a password.
1 |
[devopsclient@devops-team ~]$ ssh devopsserver@192.168.1.11 |
Conclusion
In this post, i have explained How to connect in SSH without password.
If you have any questions or feedback, feel free to leave a comment.
As always, if you found this post useful, then click like and share it 🙂