How To Generate and Use SSH Private & Public Keys

You can use a public-private key pair to secure SSH access to your cloud server. A public key is placed on the server, and the private key is placed on your local workstation.

This makes it impossible for someone to log in using just a password, as long as you set up SSH to deny password-based authentication.

How to generate a key

Windows:

First, download PuTTYgen and use it to generate your public and private keys.

  1. Launch the program and click Generate. The program will generates keys for you.
  2. Enter a unique key passphrase in Key passphrase and Confirm passphrase fields. Leave empty if you do not want to use the passphrase.
  3. Save your keys by clicking Save public key and Save private key.
  4. Copy the text under Public key for pasting into the OpenSSH authorized_keys to your clipboard using the Ctrl+C key combination. Paste the key either in the Terminal or directly into the authorized keys section on your Cloud Server.
Video showing how to generate public and private key using PuTTY Key Generator.

Unix-like operating systems:

This applies to macOS, Linux and other Unix-like OS. As an example, we use macOS.

  1. Access the Terminal, which you can find via Search.
  2. Enter the following command in the Terminal window:
    ssh-keygen -t rsa 
  3. Choose a file path where your keys will be saved. You can specify a path:
    /path/to/file/filename
    Or you can press Enter to use the default path and file name, which is:
    /Users/youruser/.ssh/id_rsa
    We recommend using the default one.
  4. You can now set up a password for your key pair. You can type in your desired password. If you do not want to use a password, press Enter to leave the field blank.

Once you complete these steps, your Private and Public keys will be generated in the specified directory. You can locate and open your keys to see them in text format. The public key has the .pub extension, and you can upload it to your remote server.

NOTE: You must not share your private key with anyone.

Video showing how to generate private and public keys on Unix-like operating systems.

How to add a new public key to the list

  1. Log in to the Terminal and open the Cloud Hosting menu.
  2. Click Security to find your SSH Keys.
  3. Click Add Key, enter the key Label and then paste your public key into the Public key field. If you mark it as default, the current and all future machines will be assigned this key.
  4. Click Yes and then go back to the Security menu to confirm that your key is listed in the SSH Keys list.

Was this article helpful?

Need support?

If you need any further help, don't hesitate to send a support request to our support team.