How do I create an SSH key?

With an SSH key you can access a network device in encrypted form. A key pair consisting of a private and a public key is required for authentication. We show you how to generate these SSH keys.

What is SSH?

SSH is the abbreviation for “Secure Shell “(secure command line). Via SSH you can access another computer in the network or via the Internet in a command line, for example to manage it remotely. The small tool PuTTY works for this under Windows. In Linux this is done via the terminal.

Since you are using a simple command line program here, you do not need a graphical user interface (GUI) or mouse or keyboard or screen on the respective target computer. All this is done via SSH via a remote connection on your respective laptop or PC.

In order for an SSH transmission to be secure, an SSH key is required for what is known as public key authentication. This SSH key consists of two keys: the public and private key. You can generate them relatively easily on your computer.

Create SSH key in Linux and macOS

1st step:

Photo: GIGA
Photo: GIGA

Opens the terminal. Most of the time this works with the key combination [Strg] + [Alt] + [T]. Otherwise you can find the terminal in the start menu or in the application overview. In macOS you can find the terminal in the folder / Programs / Utilities /.

2nd step:

Photo: GIGA
Photo: GIGA

The tools for creating SSH keys are preinstalled in macOS and in many standard Linux distributions. So maybe you have to install “OpenSSH” in your Linux distribution beforehand. This can be done on a Debian-based distribution like Ubuntu or Linux Mint in the terminal with the following commands:

  • sudo apt-get install openssh-server
  • sudo systemctl enable ssh
  • sudo systemctl start ssh

Now you create the SSH key with the command:

ssh-keygen -t rsa -b 4096

The operating system now creates an SSH key according to the RSA cryptosystem with a length of 4096 bits. As things stand at the moment, the key is secure against brute force attacks.

3rd step:

Photo: GIGA
Photo: GIGA

The computer asks in which file the key should be stored. In Linux this is the hidden folder by default /home/BENUTZERNAME/.ssh/id_rsa. In macOS this is the hidden folder /Users/cren/.ssh/id_rsa. If you agree to the default setting, confirm the process with [Enter]. Otherwise, it’s best to enter a new file with a unique name. In our example we use the standard folder.

4th step:

Photo: GIGA
Photo: GIGA

Optionally, you can now protect the SSH key with a passphrase for even more security. You have to confirm this again afterwards. Otherwise you leave the fields blank and confirm twice with [Enter].

5th step:

Photo: GIGA
Photo: GIGA

The SSH key has been created as a key pair. You can open the associated files in the folder specified in step 3 with a text editor. With us the result looks like this:

  • the private Key (“Your identification”) is the file /home/jolanda/.ssh/id_rsa saved.
  • the public key (“Your public key”) is in the file /home/jolanda/.ssh/id_rsa.pub saved.

If you have used the standard folder, a dot in front of the folder name means that the folder is hidden. Under Linux you hide hidden folders in the file manager, for example with the key combination [Strg] + [H] in and out.

Attention: the private key (Private Key) must not fall into the wrong hands! Because whoever has this key can access all systems on which the associated public key is stored. The access rights of the private key should be set so that only the owner can read it.

Create an SSH key in Windows

1st step:

Photo: GIGA
Photo: GIGA

Install the PuTTY program. Then start but not PuTTY, but the installed program PuTTYgen. To do this, open the start menu, type “puttygen“And opens the displayed program.

2nd step:

Photo: GIGA
Photo: GIGA

Sets the following parameters in PuTTYgen:

  • Type of key to generate: RSA
  • Number of bits in generated key: 4096

Confirmed with the button “Generate“.

3rd step:

Photo: GIGA
Photo: GIGA

PuTTYgen now asks you to move the mouse over the free area below the progress bar in order to create the SSH key. Then you will see the result. In the fields “Key passphrase” and “Confirm passphrase” you can also set a password for the SSH key, if desired. We leave that blank in our example.

This is how you save the SSH key:

  • Click on the button “Save public key“To save the public key.
  • Click on the button “Save private key“To save the private key as a PPK file.

It is best to save both files in a folder and give each file a meaningful name. The key pair has now been created and is ready for use. If necessary, you can drag the files into an editor to view the content.

How do I use SSH keys?

When you have created the SSH key pair as described above, you copy the public key to the target computer that you want to control remotely or via the network. To do this, log in to the target computer and copy the public key in a folder of your choice. The associated terminal command is:

ssh-copy-id -i ~/Pfad/zur/Schlüsseldatei [email protected]

Adjust the folder path, your username and the server. Then you can log into the server with the following command:

ssh -i ~/Pfad/zur/Schlüsseldatei [email protected]

A password is no longer required for logging in, as the public key on the target computer matches the private key on your computer. However, if you have assigned a passphrase (password) for the SSH key, this will now also be requested.

If you did not use the standard folder when creating the SSH key, the command line may display an error. Then you should move the private key to the hidden user folder “.ssh” on your computer. Then the registration should succeed.

Open source vs. commercial software – what do you use?

You don’t want to miss any news about technology, games and pop culture? No current tests and guides? Then follow us on Facebook (GIGA Tech,
GIGA Games) or Twitter (GIGA Tech,
GIGA Games).



Reference-www.giga.de