SSH keys can be used to establish a secure connection to remote host using SSH protocol. SSH supports password-based authentication, but recommended to use SSH keys instead. This tutorial demonstrates how to generate SSH key pair in Linux.
To generate SSH key pair in Linux, run the ssh-keygen
command:
ssh-keygen
The command prompts to enter the file path in which you want to save the key. Press enter to save to the default path. Command also prompts to enter a passphrase. It allows to protect the private key. Passphrase is optional, you can leave empty and press enter. The command generates SSH key pair which consist of private key and public key. The public key filename is the private key filename with .pub
extension.
The ssh-keygen
command supports various options. For example, to generate 4096-bit RSA key pair, run the following command:
ssh-keygen -t rsa -b 4096
By default, id_rsa
private key and id_rsa.pub
public key will be save to ~/.ssh
directory. The -f
option allows to specify the filename of the key file:
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_vps
Leave a Comment
Cancel reply