How to find or generate a SSH key on Linux system

To find or generate a SSH key on Linux system

  1. Check for existing SSH keys on your computer. Skip to Step 4 if you already have one and want to use that one.

    First, we will check for existing ssh keys:

    $ cd ~/.ssh

  2. Backup and remove existing SSH keys to create one.

    If there is already a SSH directory you’ll want to back the old one up and remove it. $ ls Lists all the subdirectories in the current ssh directory

    $ ls
    config id_rsa id_rsa.pub known_hosts

    Make a subdirectory called “key_backup” in the current directory

    $ mkdir key_backup

    Copy the id_rsa and id_rsa.pub files into key_backup

    $ cp id_rsa* key_backup

    Remove existing SSH directory and key.

    $ rm id_rsa*

  3. Generate a new SSH key. To generate a new SSH key, enter the code below. We will create new key in the current directory so when asked to enter a file in which to save the key, just press enter.

    $ ssh-keygen -t rsa -C "your_email@youremail.com"
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa):<press enter>

    Now you need to enter a passphrase.

    Enter passphrase (empty for no passphrase):<enter a passphrase>
    Enter same passphrase again:<enter passphrase again>

    Which should give you something like this:

    Your identification has been saved in /root/.ssh/id_rsa.
    Your public key has been saved in /root/.ssh/id_rsa.
    The key fingerprint is:
    01:0f:f4:3b:ca:85:d6:12:a1:7d:f2:64:9d:f0:a2:db user_name@username.com
    The key's randomart image is:

      +--[ RSA 2048]----+
      |         .+* +o. |
      |          . +EXo |
      |             O.=o|
      |            +o=o.|
      |        S   oo  .|
      |         . .     |
      |          .      |
      |                 |
      |                 |
      +-----------------+
  4. Go to the location where your SSH key is saved and open it

    $ gedit /root/.ssh/id_rsa.pub

    Everything in this file is your SSH key. It looks something like,

    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDNG2SI+C7y4KvCwR2YC2vFmmHCrHkMulfzfZRxbY+Yp2SxbUG4umBuk7aRp+5A1/8fvEA9WTY0z+E+7M10y6108HnjXqF7j+9cRlVqdaaroW9T6xz3C5efHLTuhSfGtYJ1BGprrnhsBWSPC2JKB6zK9RZ7pIXXAUbIyHaokcgcs7xofAqLoeLdE2ER9HmrZTj17wELHsJzztB4jJBGr4wWXTcb82gbb0B12nkbATpTzYVtlpLT1PnlJLsoNuvw3ZGwx8GmMWulOFFL7IfrT0tbajKZfvlXT22Y1Wixuq3YFjltS5OQjgPC4LQTeWb+qvB2Lj6mrvJsVCeOkKmGrZ/J
    your_email@youremail.com

Leave a Reply

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