Secure Shell (SSH) is a trusted and open source network protocol used for remote server login and command execution. SSH is also used to transfer files from one computer to another computer and download files from remote server to local computer using SCP (secure copy) protocol.
SSH can be enabled in two ways
- Key-based authentication
- Password-based authentication
Key-based authentication is commonly known as passwordless login.
In this article, we will explain how to enable passwordless login using ssh-keygen and ssh-copy-id.
ssh-keygen generates private and public keys and ssh-copy-id copies the local host’s public key to the remote server’s authorized_keys files. Ssh-copy-id assigns the proper permission to the remote host automatically.
Generate ssh key pair using ssh-keygen and copy to remote host
Run the following command to generate public and private keys.
You will be asked to set the directory to store the key file and passphrase. Just press enter to set the default in each step and continue.
In the user’s home directory run the following command to list the generated files.
$ cd ~/.ssh
You can see the id_rsa and id_rsa.pub file. Id_rsa is a private key file, which you need to keep secret. Whereas, id_rsa.pub is a public key file that needs to be copied to a remote server.
Now run the following command to copy the public key to the remote host.
$ ssh-copy-id [email protected]_host_ip
$ ssh-copy-id [email protected]
Now try login without providing a password
$ ssh [email protected]_host_ip
$ ssh [email protected]
The output shows that the passwordless login has been successful. You don’t have to enter a password.
You can also copy the content of id_rsa manually and paste inside authorized_keys file of the remote server. This is what the ssh-copy-id does for you.
In this article, we learned how to enable ssh passwordless login using ssh-keygen and ssh-copy-id. If you have any suggestions and feedback, please drop a comment below.
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.