View Categories

How to generate and use SSH keys on Linux

1 min read

Table of Contents

This guide will help you with generating SSH keys and using them inside a Linux server.

Step 1 #

Inside Linux shell type:

$ ssh-keygen

and hit Enter. You will be asked for key location:

$ Enter file in which to save the key (/root/.ssh/id_rsa):

You can save it in default location (/root/.ssh/id_rsa).
Please now set a password for your id_rsa key:

$ Enter passphrase (empty for no passphrase): $ Enter same passphrase again:

Your id_rsa key should be now generated:

Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:D+3Z5f1sJ1uQ0M6mFG7U5I8F6qXdFAYI/ELfzXbDEek root@localhost
The key's randomart image is:
+---[RSA 2048]----+
| ... ..++o|
| o . *.+.|
| . o * X +|
| o * X E.|
| S o * @ =|
| + = = o |
| + o . o|
| .o+|
| .++|
+----[SHA256]-----+

 

Step 2 #

You can install your pub key inside other Linux server by using the command:

$ ssh-copy-id root@server

After login to another Linux server, your key will be automatically installed inside ~./.ssh/authorized_keys

You can also copy your pub key by typing:

$ cat .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDDQAjNWVoychQ7BQn0qOJeg2aXx65usEs3lqBGRDjFJo7rtGT4tjRq3q1c1mnY
k+ZxFCgDPmNuX5RlTBYqqDN0L97HDOYe20q2BkwgUuOLNKlG4Vn6+IBS9iVyK0ccY5Fk2mbh3JzGmIAkwKoXoHkChOzlRWbweS+b
OUyj3L+XrjPYi+DaSdPKyQ9ZHEAKU4DSljC35LCUkut6HfQfnvz7zjPeogrirNaCghaHBxI0HstndpPrmwabSs/W0BsTcO7jDk/O
fzVTz9ay5PXuYoYIQduGLqO2JZr7KrFkGWhnoMMr7ntkvweNGXZnVyeH+xB42OYvE6WI4Aa9Zf3uKTYd root@localhost

Now you are able to login to another machine with your generated id_rsa key.