When working with servers, you will often encounter a need to log in to manage them remotely, and you can do this by establishing an SSH connection.

Although it is possible to use simple passwords for your SSH connection, it is recommended to use SSH keys for enhanced security.

To generate an SSH key, follow the steps below:

Step 1: Open a Terminal

  • On Linux: You can open Terminal by pressing Ctrl+Alt+T.
  • On Mac: You can open Terminal by navigating to Applications -> Utilities -> Terminal.
  • On Windows: You can open Command Prompt by searching for it in the Start Menu.

Step 2: Generate an SSH Key

The process of generating an SSH key is extremely simple – all you need to do is run the ssh-keygen command and the built-in utility will automatically create a new key for you.

Optionally, you can specify additional parameters with your command to configure the key in a certain way. For example, in the following command we have specified the encryption algorithm, the number of bytes for the key, and a comment which can be used to distinguish different keys. Although the comment can be anything, it is customary to use an email address for this field.

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Replace "[email protected]" with your email address and execute it in your terminal window. This command will create a new SSH key with 4096 bits.

When you’re prompted to “Enter a file in which to save the key,” press Enter. This stores the file in the default location. Alternatively, you can provide a different path and the name for your SSH key.

Next, you will be asked to enter a secure passphrase. Since an SSH key is your identity, any person who is able to get their hands on the secret key will be able to impersonate you, so it is recommended to use a secure password for storing your keys.

Step 3: Changing permissions

When an SSH key is created, it is treated as a general file and has ‘open’ permissions, i.e. anybody can read your keys. To use it with any SSH software, you need to reduce the permission level of your key by using the following command:

chmod 600 <path-to-private-key>

That’s it! You’ve successfully generated an SSH key on your Linux or Mac computer. Now you need to keep your private key secure and only share your public key with others.

Step 4 : Sharing Public keys

Your public key is located in the same directory as your private key and has the same filename but with a .pub extension. For example, if the name of your key is my_key then the public key will be named my_key.pub.

You can open your public key using any file editor such as notepad. If you’re working in the terminal, you can use a terminal-based text editor such as nano, or simply use the cat command as shown below:

cat <path-to-public-key>

The above command will display a long string of characters. You can store this key in your RunCloud key vault to quickly access your servers.