How to Create SSH Keys for Linux
An SSH key is an access credential utilized for the SSH protocol. Its function is similar to that of user names and passwords, but the keys are primarily used for accessing servers via the command line.
Create SSH Key
To create and SSH key on Linux we can use the command ssh-keygen.
ssh-keygen
After pressing enter you will then be promted with the question to name the location of the file.
Enter file in which to save the key (/home/me/.ssh/mykeyname):
/home/me/.ssh/mykeyname
Now it is time to select a password for your SSH key. This password will be asked for when the key is utilized in the future. If you do not want a password for the key, simply leave it blank.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
When you have finished entering your password, a public and a private key will be created.
Your identification has been saved in /home/me/.ssh/mykeyname
Your public key has been saved in /home/me/.ssh/mykeyname.pub
The key fingerprint is:
SHA256:dzE12DVnHlqX47/nukMyVkZJs6KQirNp0D4GDEjFkl0 me@fedora
The key's randomart image is:
+---[RSA 3072]----+
| .=..E +=**|
|oo o . ..*O=|
|o . o +oo o|
| o . . . . . +o. |
| + + . S o .o .|
| + + . .+ . .|
| B . + .|
| o . ...|
| o=o|
+----[SHA256]-----+
The newley created key is now located in the ~/.ssh
under the name the name you specified, mykeyname and mykeyname.pub.
Add SSH key to key-ring
To be able to use the SSH key we should add it to the key-ring. We can do so with the following command.
ssh-add ~/.ssh/mykeyname
To use the public key you can simply copy mykeyname.pub
cat ~/.ssh/mykeyname.pub