Set Up Passwordless SSH Login Using ssh-keygen - How to do it ?

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 namely, Key-based authentication and Password-based authentication.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related SSH queries.

In this context, we shall look into 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.

How to Generate ssh key pair using ssh-keygen and copy to remote host ?

In order to generate public and private keys, simply execute the below command:

$ ssh-keygen

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 file. Id_rsa is a private key file, which you need to keep secret. Whereas, 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.

It's Syntax is given below:

$ ssh-copy-id user@remote_host_ip

For Example:

$ ssh-copy-id root@

Now try login without providing a password

$ ssh user@remote_host_ip


$ ssh root@

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.

[Need assistance in fixing SSH terminal Linux issues? We can help you. ]

This article covers how to enable ssh passwordless login using ssh-keygen and ssh-copy-id. In fact, SSH (Secure SHELL) can be used to transfer files from one computer to another computer over the network using a secure copy (SCP) Protocol.

ssh-keygen creates the public and private keys. ssh-copy-id copies the local-host's public key to the remote-host's authorized_keys file. ssh-copy-id also assigns proper permission to the remote-host's home, ~/.ssh, and ~/.ssh/authorized_keys.

Related Posts