How To Generate and Use SSH Private & Public Keys - Heficed (2024)

Tutorials > 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.
How To Generate and Use SSH Private & Public Keys - Heficed (1)

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.

How To Generate and Use SSH Private & Public Keys - Heficed (2)

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.

I'm an expert in the field of secure shell (SSH) protocols and key management, with a demonstrable understanding of the intricacies involved in setting up and maintaining secure access to cloud servers. My expertise stems from practical experience and a deep knowledge of the concepts discussed in the provided article.

In the realm of SSH, I understand the critical importance of employing public-private key pairs to enhance security, preventing unauthorized access to cloud servers. This involves placing a public key on the server while safeguarding the corresponding private key on the local workstation. By doing so, the reliance on password-based authentication is eliminated, significantly bolstering the overall security posture.

The article primarily covers the generation and utilization of SSH keys on both Windows and Unix-like operating systems. For Windows users, the recommendation is to use PuTTYgen to generate the key pair. The process involves launching the program, generating keys, setting a passphrase for added security, and then saving the public and private keys. The public key can then be copied and pasted into the authorized_keys section on the cloud server.

On Unix-like operating systems, such as macOS or Linux, the article details the command-line approach using ssh-keygen. Users are instructed to enter a command in the Terminal, choose a file path for key storage, and optionally set a password. The resulting private and public keys are then generated and can be located in the specified directory, with the public key having a .pub extension. This public key is what users upload to their remote server.

Crucially, the article emphasizes the importance of not sharing the private key with anyone, recognizing it as a sensitive piece of information crucial to maintaining the integrity of the key pair.

The article also briefly touches on the process of adding a new public key to the SSH Keys list on the cloud server. Users are guided through the steps of logging into the Terminal, accessing the Cloud Hosting menu, and adding a new key by providing a label and pasting the public key. The option to mark the key as default for future machines is also mentioned.

In addition to key generation and addition, the article briefly introduces related topics such as IP addresses and VPS (Virtual Private Servers), expanding the reader's understanding of the broader context of secure server management.

For users seeking further assistance, the article offers a support team contact option, indicating a commitment to helping users navigate any challenges they may encounter in implementing these security measures.

How To Generate and Use SSH Private & Public Keys - Heficed (2024)
Top Articles
Latest Posts
Article information

Author: Trent Wehner

Last Updated:

Views: 6084

Rating: 4.6 / 5 (76 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Trent Wehner

Birthday: 1993-03-14

Address: 872 Kevin Squares, New Codyville, AK 01785-0416

Phone: +18698800304764

Job: Senior Farming Developer

Hobby: Paintball, Calligraphy, Hunting, Flying disc, Lapidary, Rafting, Inline skating

Introduction: My name is Trent Wehner, I am a talented, brainy, zealous, light, funny, gleaming, attractive person who loves writing and wants to share my knowledge and understanding with you.