Rate this post

Last Updated on May 22, 2021 by Vikash Ekka

How to use the ssh-keygen Command in Linux

Secure Shell (also known as SSH) is a cryptographic network protocol. Ssh-keygen is a tool in the Linux distro that is used for creating new authentication key pairs for SSH. Such key pairs are used for automating logins, single sign-on, and for authenticating hosts. In simple word, ssh keygen allow a user to connect to a remote system without supplying a password

It is also used to transfer files from one computer to another computer over the network using a secure copy (SCP) Protocol.

In this tutorial post, we will show you how to set up and use password-less login on Linux/Ubuntu, RHEL/CentOS, and Fedora using ssh keys to connect to remote Linux servers without entering a password. By using Password-less login with SSH keys will increase the trust-relation between two Linux servers for easy file synchronization or transfer.

In this example, we will set up SSH password-less automatic login from server as user sr to with user server.

Note:- Username in First Server is :- sr

           Username in Second Server is :- server

In your case IP address’s and username would be different

Step 1: Create Authentication RSA SSH-Keygen Keys on – (

First login into server with user sr and generate a pair of public keys using the following command.

sr@vetechno:~$ ssh-keygen -t rsa

How to use the ssh-keygen Command in Linux

Step 2: Now we create .ssh Directory on –

Use SSH from server to connect server using server as a user and create .ssh directory under it, using the following command.

Note:- Username in First Server is :- sr

          Username in Second Server is :- server

ssh [email protected] mkdir -p .ssh

How to use the ssh-keygen Command in Linux

Step 3: Upload/Move Generated Public Keys to Second Server –

Now use SSH from First Server and upload a new generated public key (id_rsa.pub) on Second Server under server‘s .ssh directory as a file name authorized_keys.

sr@vetechno:~$ cat .ssh/id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys'
How to use the ssh-keygen Command in Linux
Step 4: Now we need to set Permissions on Second Server –

Set the remote ~/.ssh directory permissions to 700. Due to different SSH versions on servers, we need to set permissions on .ssh directory and authorized_keys file.

ssh [email protected] "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
How to use the ssh-keygen Command in Linux

Step 5: Login from First Server – to Second Server – Server without Password

From now onwards you can log into Second Server as server user from First server as sr user without a password.

ssh [email protected]
How to use the ssh-keygen Command in LinuxHow to use the ssh-keygen Command in Linux


Congratulations you have successfully generated RSA ssh keygen to login server without 

Related Search Queries 

generate ssh key ubuntu, generate ssh key ubuntu 20, how to find ssh key in ubuntu, generate ssh key linux, ubuntu generate ssh key for git, copy ssh key ubuntu, generate ssh key ubuntu gitlab, ubuntu import ssh key.

Also Read:- How To Install Linux, Apache, MySQL, PHP (LAMP) on Ubuntu

Also Read:-  How to Install MySQL 8.0 on Ubuntu 16.04 LTS ??

Also Read:- Uninstall or Remove MySql 5.7 from Ubuntu 20.04 LTS.

By Vikash Ekka

Hi All, My name is Vikash Ekka from India. I’m the founder and tech editor of https://www.vetechno.in. I have completed my Graduation in BCA. I love to write technical articles like Windows, Linux & MAC Tutorials, Tips, Tricks, How To fix, Tutorials About Ethical Hacking & Cyber Security Guide, and Software Review. Currently, I have been working as an IT professional since 2018.

Leave a Reply

Your email address will not be published. Required fields are marked *