×



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 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.

It's Syntax is given below:

$ ssh-copy-id user@remote_host_ip

For Example:

$ ssh-copy-id root@192.168.178.120

Now try login without providing a password

$ ssh user@remote_host_ip

Example

$ ssh root@192.168.178.120

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. ]


Conclusion


More Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on IbmiMedia.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com