How To Generate SSH Key With ssh-keygen In Linux
How To Generate SSH Key With ssh-keygen In Linux
- GeeksforGeeks
Table of Content
How does SSH work?
What is SSH-KEYGEN?
Files generated by ssh-keygen
Generating SSH Key Pairs Using ssh-keygen
Copying Public key to the remote server
Method 1: Using ssh-copy-id
Method 2: Manually copying the public key
This process ensures that the client-server connection is secure, and only the
authorized client (with the private key) can access the remote server.
https://www.geeksforgeeks.org/how-to-generate-ssh-key-with-ssh-keygen-in-linux/ 1/5
2/22/25, 12:52 PM How To Generate SSH Key With ssh-keygen In Linux? - GeeksforGeeks
What is SSH-KEYGEN?
ssh-keygen is the utility used to generate, manage, and convert authentication keys for
SSH. ssh-keygen comes installed with SSH in most of the operating systems. ssh-
keygen is able to generate a key using one of three different digital signature algorithms.
$HOME/.ssh/identity: File containing the RSA private key when using SSH protocol
version 1.
$HOME/.ssh/identity.pub: File containing the RSA public key for authentication
when you are using the SSH protocol version
$HOME/.ssh/id_dsa: File containing the protocol version 2 DSA authentication
identity of the user.
$HOME/.ssh/id_dsa.pub: File containing the DSA public key for authentication when
you are using the SSH protocol version.
$HOME/.ssh/id_rsa: File containing the protocol version 2 RSA authentication
identity of the user. This file should not be readable by anyone but the user.
$HOME/.ssh/id_rsa.pub: File containing the protocol version 2 RSA public key for
authentication.
https://www.geeksforgeeks.org/how-to-generate-ssh-key-with-ssh-keygen-in-linux/ 2/5
2/22/25, 12:52 PM How To Generate SSH Key With ssh-keygen In Linux? - GeeksforGeeks
ssh-keygen
It asks for the names of the ssh key pairs. If you wish to enter the passphrase, go on
and ssh-keygen will automatically create your keys.
//Output
https://www.geeksforgeeks.org/how-to-generate-ssh-key-with-ssh-keygen-in-linux/ 3/5
2/22/25, 12:52 PM How To Generate SSH Key With ssh-keygen In Linux? - GeeksforGeeks
This is the key you need to copy into your remote device to get successful SSH
authentication.
Use the “ssh-copy-id” command to copy your public key file (e.g.,
$HOME/.ssh/id_rsa.pub) to your user account on the remote server.
https://www.geeksforgeeks.org/how-to-generate-ssh-key-with-ssh-keygen-in-linux/ 4/5
2/22/25, 12:52 PM How To Generate SSH Key With ssh-keygen In Linux? - GeeksforGeeks
Login to your remote server using the password and create a directory at $HOME/.ssh.
You can use the command below.
ssh <user>@<host> allows you to login into your remote host server
If the .ssh directory is already present, it will set the permissions of the directory to
077 so that it allows read, write, and execute permission for the file’s owner, but
prohibits reading, writing, and execute permission for everyone else.
If the directory is not present, then it will create a new one.
cat allows you to print the contents of the file in the terminal.
The output from the cat is piped into SSH to append the public key to a remote
server.
Now you can logout and test whether you can connect to the remote server using the
SSH protocol.
Conclusion
Setting up SSH and using ssh-keygen to generate key pairs simplifies and secures the
process of accessing remote servers. By following the steps outlined in this guide, you
can create a passwordless authentication system for SSH, significantly improving your
remote management efficiency.
https://www.geeksforgeeks.org/how-to-generate-ssh-key-with-ssh-keygen-in-linux/ 5/5