HomeHow to

How To Create SSH Key On Linux & Windows

How To Create SSH Key On Linux & Windows
Like Tweet Pin it Share Share Email

With SSH, it is possible to establish a secure connection to a network device. With an SSH key, you provide the necessary security.

SSH, the short form of “Secure Shell” is a practical matter: Using the terminal – or in Windows systems with the help of the small tool PuTTY – you can use SSH to remotely manage another computer via command line. This is always practical when Unix-based systems – such as a media center PC, a crafting computer, a server or web server or a NAS – are involved. Thanks to SSH, the systems do not need a user interface and no keyboard and mouse connected, nor a screen: SSH remotely controls the terminal, conveniently from a laptop or PC. For this to work smoothly and safely, an SSH key should be set up for the so-called public-key authentication: This consists of a key pair in the form of a public and a private key and ensures a secure login.

Create SSH key under Linux and macOS: That’s how it works

To create an SSH key on Unix systems such as Linux or macOS, the so-called terminal is important. This is the command line within the graphical interface of the system. Who uses Linux without surface, can also use the respective shell – here there is no difference.

Step 1: Open a terminal window. This can be found in most Linux interfaces in the ” Start menu ” or the menu bar. In macOS, you will find it in the folder / Applications / Utilities/.

Step 2: On Linux, you may need to install OpenSSH in more puristic distributions, macOS and the most standard district already have SSH key creation on board. First, enter the ssh-keygen -t rsa -b 4096 commands. This creates a key after the 4096-bit RSA cryptosystem. Thus, the key by brute force is hard to crack.

Step 3: The computer now asks in which file the key should be stored. It is best to specify a new file that is uniquely named. The default in macOS is that the key will otherwise end up in the default file, and that is confusing; especially since the folder “.ssh” is hidden. Confirm with the enter key.

Step 4: You can now additionally assign a password for even more security , but this is not absolutely necessary. If you want to use a password for the key, you can enter it and then confirm it. Otherwise, you can skip this option with the Enter key. At this point we create a key pair without an additional password.

Step 5: That’s it: The key pair is created and is in the file specified in step 3. You can open these later with a text editor (in the terminal vi, under macOS any editor, such as CotEditor to view and use the key pair.

To create an SSH key on Windows

Even under Windows, creating an SSH key is no problem. But first you have to install the free tool PuTTY . Then you can start creating the key.

To generate an SSH key with PuTTYgen, follow these steps:

  1. Open the PuTTYgen program.
  2. For Type of key to generate, select SSH-2 RSA.
  3. Click the Generate button.
  4. Move your mouse in the area below the progress bar. When the progress bar is full, PuTTYgen generates your key pair.
  5. Type a passphrase in the Key passphrase field. Type the same passphrase in the Confirm passphrase field. You can use a key without a passphrase, but this is not recommended.
  6. Click the Save private key button to save the private key.  You must save the private key. You will need it to connect to your machine.
  7. Right-click in the text field labeled Public key for pasting into OpenSSH authorized_keys file and choose Select All.
  8. Right-click again in the same text field and choose Copy.

What to do with the SSH keys?

When the key pairs are created, nothing stands in the way of their use. Since the creation of the “control computer”, so the laptop or PC has been done, the public key must still be copied to the server. First, you have to log in to the server and then put the key there. The required command in the terminal is: 

ssh-copy-id -i ~ / path / to / keyfile user @ server

The paths and users must, of course, be adapted to your conditions. 

You can then use 

ssh -i ~ / path / to / keyfile user @ server

log in to the server. A password is no longer needed in the set setting, as the private and public key match. Maybe the command line complains that the key does not exist. In this case, you need to move the file with the private key to the hidden user subfolder .ssh on your “control system”.

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *