To find or generate a SSH key on Linux system
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
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.
$ lsLists all the subdirectories in the current ssh directory
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*
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 "firstname.lastname@example.org"
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:
The key's randomart image is:1234567891011+--[ RSA 2048]----+| .+* +o. || . +EXo || O.=o|| +o=o.|| S oo .|| . . || . || || |+-----------------+
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,