# Generate and use an SSH key

In this guide you'll learn how to generate an ssh key to connect to other Unix/Linux hosts.

# Using OpenSSH

This is probably what you are using if your station is a Linux or BSD computer. You will probably want a ed25519 key or an RSA 4096 bit key unless you care about local regulations.

Run:

$ ssh-keygen -t ed25519
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/user/.ssh/id_ed25519):

When prompted for the file to store the key, you can press Enter if you don't have any key yet. If the file exists, it will be overwritten with no recovery possible.

As it is better to use different keys for different users, better use a custom name. The path and name are relative to your current directory. It's best to store your ssh keys in /home/user/.ssh .

For example, the key user for connecting to your host4coins server could be: /home/user/.ssh/id_ed25519_h4c

Take also a moment to think about your passphrase. The passphrase protects your key from being used if you leak the private key file. It has to be long and strong.

Then you can resume the interaction with ssh-keygen:

Enter file in which to save the key (/root/.ssh/id_ed25519): /home/user/.ssh/id_ed25519_h4c
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_ed25519_h4c.
Your public key has been saved in /home/user/.ssh/id_ed25519_h4c.pub.
The key fingerprint is:
SHA256:63leeZQhfHnpGHHGHGHGHGHgYGjvLQLhg73k/dJpNoQoI user@host
The key's randomart image is:
+--[ED25519 256]--+
|                 |
|   .       .   ..|
| .o .       o +..|
|=... o       o.+ |
|EB .. . S    .o. |
|= =   oo+.  .o.  |
|.o.. +.=+* .o .  |
| . .+  +*=+. .   |
|    ....*=o      |
+----[SHA256]-----+

Now you have:

  • your passphrase
  • /home/user/.ssh/id_ed25519_h4c - the private key to save and never disclose
  • /home/user/.ssh/id_ed25519_h4c.pub - the public key

When asked for your ssh key to connect to some service, you give the content of the public key.

Then, to connect to "server" using your key as user "user", type:

ssh -i .ssh/id_ed25519_h4c user@server

You will then be prompted for your passphrase.