Generate SSH keypair

You can easily create an SSH key pair by using ssh-keygen as in the following example.

$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
1a:6c:a4:94:df:e0:19:ec:85:b0:3f:27:e4:a1:de:65 user@host
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|   .             |
|    o E          |
|     O o         |
|    c @ S        |
|   o A @         |
|    . E .        |
|   . =           |
|    .            |
+-----------------+

There are a few things that you might want need to take note;

  1. A 2048 bit RSA key pair will be generated by default. You can use different key type by using -t option and specify any of the supported key types
    dsa ecdsa ed25519 rsa rsa1
  2. The private key will be stored in ~/.ssh/id_rsa while the public key will be stored in ~/.ssh/id_rsa.pub. You can specify other location when prompted during the key generation process if you already have a key pair at the default location
  3. You can specify passphrase for your key pair when prompted but you'll have to not set the passphrase to use passwordless SSH login

Sign up for Complete Secure Shell Course and many other great courses on Udemy to learn more.


Written by Mohd Shakir Zakaria. Last updated on 2019-02-12