Generate public SSH key from private SSH key - Experiencing Technology (2024)

Posted on 2016-02-15 by Gerhard

Generate public SSH key from private SSH key - Experiencing Technology (1)A lost SSH public-key or a web service generates anSSH key but does not provide the public-key part to you. What to do now? There is a solution for this situation.

When you have an SSH key you need the public key to setup SSH passwordless login with SSH-key. But if you have lost the public key part but still have the private key, there is a way to regenerate the key.

With the public key missing, the following command will show you that there is no public key for this SSH key.

$ ssh-keygen -l -f ~/.ssh/id_rsatest is not a public key file.

The -l option instructs to show the fingerprint in the public key while the -f option specifies the file of the key to list the fingerprint for.

To generate the missing publickey again from the private key, the following command will generate the public key of the privatekey provided with the -f option.

$ ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pubEnter passphrase:

The -y option will read a private SSH key file and prints an SSH public key to stdout. The public key part is redirected to the file with the same name as the private key but with the .pub file extension. If the key has a password set, the password will be required to generate the public key.

To check the details of the generated public key execute the following command as shown above.

$ ssh-keygen -l -f ~/.ssh/id_rsa4096 d6:7b:c7:7a:4f:3c:4d:29:54:62:5f:2c:58:b2:cb:86 ~/.ssh/id_rsa (RSA)

The output of this command shows the key size as the first column, the fingerprint as the second column and after the file name, the type is shown in brackets. In the example above, a 4096 bit RSA key.

Read more of my posts on my blog at http://blog.tinned-software.net/.

This entry was posted in Linux Administration, Security and tagged SSH, ssh key. Bookmark the permalink.

I've worked extensively with SSH keys and their management, so I can provide insight into the concepts discussed in the article you mentioned.

The article addresses scenarios related to SSH keys, particularly focusing on managing keys when the public key part is missing but the private key is available. This situation arises when setting up SSH passwordless login, and it's crucial to have both the public and private keys. Here's a breakdown of the concepts:

  1. SSH Keys: SSH (Secure Shell) keys consist of a public and a private key. They are used for secure communication between systems over an unsecured network.

  2. Public and Private Keys: The public key is shared with remote servers or services you want to access securely, while the private key remains only on your local machine. Losing the public key part can disrupt secure access.

  3. Regenerating Public Key from Private Key: The article details the process of regenerating the public key from the available private key. The command ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub generates the public key from the private key and stores it in a file with the .pub extension.

  4. Command Breakdown:

    • -y option: Reads the private SSH key file and outputs the corresponding public key.
    • -f option: Specifies the file of the private key to use.
    • ~/.ssh/id_rsa: File path for the private key.
  5. Checking Public Key Details: The command ssh-keygen -l -f ~/.ssh/id_rsa verifies the details of the generated public key. It displays the key size, fingerprint, and type (RSA in the example provided).

  6. Key Security: SSH keys should be handled securely. Passphrases can be set for added security to protect private keys.

  7. Related Topics:

    • SSH Passwordless Login
    • Restricting SSH login to specific IP addresses
    • Troubleshooting SSH key authentication issues
    • Using SSH agent for key management
    • Securely accessing SSH servers without direct internet connections

The article belongs to the realm of Linux administration and security, covering fundamental SSH key management practices essential for secure remote access. If you want to dive deeper into these concepts, exploring the blog mentioned in the article could provide more in-depth guidance and additional related posts on SSH key management.

Generate public SSH key from private SSH key - Experiencing Technology (2024)

FAQs

How to generate public key from private SSH key? ›

To generate the missing public key again from the private key, the following command will generate the public key of the private key provided with the -f option. $ ssh-keygen -y -f ~/. ssh/id_rsa > ~/. ssh/id_rsa.

How is a public key generated from a private key? ›

Public keys are created using an asymmetric algorithm, which pairs the public key with an associated private key. The most common algorithms used to generate public keys are Rivest-Shamir-Adleman, elliptic curve cryptography and Digital Signature Algorithm.

What is the built in command that can generate the SSH public and private key files on Windows 10 Linux and MacOS? ›

Use the ssh-keygen command to generate SSH public and private key files. By default, these files are created in the ~/. ssh directory. You can specify a different location, and an optional password (passphrase) to access the private key file.

How to generate ssh key rsa 2048? ›

Create an SSH key pair on Microsoft Windows
  1. Download PuTTy Key Generator PuTTygen.exe file and run it.
  2. In the Key menu, select SSH-2 RSA Key.
  3. In Parameters, select the RSA option.
  4. In Number of bits in generated key field, enter at least 2048, ideally 4096.
  5. In Actions, select Generate.
  6. A progress bar appears.
May 24, 2024

Can you extract a public key from a private key? ›

since the public ssh key is part of the private ssh key we can extract the public key from the private; to do this we use the ssh-keygen command vs the private key. -y : This option will read a private OpenSSH format file and print an OpenSSH public key to stdout. -f: The filename of the key file.

Can you regenerate a public key from a private key? ›

In this article, we've looked at how we can generate the public key from a given private key using different command-line tools. We've started by demonstrating the ssh-keygen command, which allows us to also convert the public key into different formats in addition to generating it.

How to generate public key from private key using OpenSSL? ›

Procedure
  1. Once installed, run the OpenSSL command prompt. Type openssl to start the application.
  2. To generate a new RSA private key, type: genrsa -out {path_to_pem_file} 2048. ...
  3. To generate a public key, type: rsa -pubout -in {path_private_pem} -out (path_public_pem)

Does a private key always generate the same public key? ›

No, the hash of a private key cannot be used as the public key. In most cryptographic systems like in elliptic curve cryptography (ECC) or RSA, the public key is derived from the private key but through a specific mathematical process, not through a simple hashing mechanism.

How to generate ssh key in Command Prompt? ›

Creating SSH Keys (Command Line)
  1. Create a .ssh in your home directory. Create a .ssh folder in your user account's home directory if it does not exist: $ mkdir /home/username/.ssh. ...
  2. Run ssh-keygen to generate an SSH key-pair. ...
  3. Retrieve the public key file. ...
  4. Start a transfer using public key authentication with the ascp command.

How to generate ssh public key using PuTTY? ›

Generating SSH key pairs locally
  1. Download PuTTYgen (available here) and run the executable.
  2. Click on the Generate button and follow on-screen instructions.
  3. Create and confirm a Key passphrase.
  4. Save public and private keys. Saving the public key with the extension . ...
  5. Upload the public key file.

How to login to ssh with a private key? ›

How to use a Private key for SSH authentication
  1. Step 1 : Check to see if you already have an SSH key. $ ls ~/.ssh. ...
  2. Step 2 : Create SSH key. $ ssh-keygen. ...
  3. Step 3 : Copy public key to the remote host. $ ls ~/.ssh. ...
  4. Step 4 : SSH using The Private Key. ...
  5. 10 thoughts on - How to use a Private key for SSH authentication.

What is a SSH key and how to generate a SSH key? ›

Generate an SSH Key Pair
  1. Run the ssh-keygen command. You can use the -t option to specify the type of key to create. ...
  2. The command prompts you to enter the path to the file in which you want to save the key. ...
  3. The command prompts you to enter a passphrase. ...
  4. When prompted, enter the passphrase again to confirm it.

How to generate RSA public and private keys in Windows? ›

Windows Users
  1. Start the PuTTYgen utility, by double-clicking on its .exe file.
  2. For Type of key to generate, select RSA.
  3. In the Number of bits in a generated key field, specify either 2048 or 4096 (increasing the bits makes it harder to crack the key by brute-force methods. ...
  4. Click the Generate button.
Mar 1, 2024

How to generate public and private key in Linux? ›

Procedure
  1. In a terminal, run the ssh-keygen command.
  2. Generate the public/private RSA key pair.
  3. Specify the directory in which to save the key pair. For example, /Users/mymac/. ssh/id_rsa... mysftpkey.
  4. Enter the passphrase. Then, enter the same passphrase again. Enter empty if you don't want to use a passphrase.

How do I get a public key from a private key in PuTTY? ›

The private key must be kept secret.

If in doubt, do not use public key authentication. You can recover the public key from the private key with PuTTYgen by clicking the Load button. You can not recover the private key from the public key however.

How to generate RSA public key? ›

Generate RSA Keys
  1. Open a shell using Putty or another utility.
  2. Use commands to generate an RSA key file. Type the following command to generate RSA keys: ssh-keygen -t rsa. ...
  3. Navigate to the. rsakey. folder that you created in step 2b. ...
  4. Locate the public key beginning with. ssh. and copy the key.

How to access ssh using private key? ›

Log in with a private key
  1. Using a text editor, create a file in which to store your private key. ...
  2. To edit the file in vim, type the following command: vim deployment_key.txt.
  3. After the editor starts, press i to turn on insert mode.
  4. To save your changes, press Esc.
  5. Type :wq to write the file and return to the command line.

Top Articles
Superalgos - Pinbar Rejection
IXL - Common Core math standards
Craigslist Free En Dallas Tx
Food King El Paso Ads
Gamevault Agent
Comforting Nectar Bee Swarm
Wmu Course Offerings
Ati Capstone Orientation Video Quiz
How to Type German letters ä, ö, ü and the ß on your Keyboard
Sunday World Northern Ireland
13 The Musical Common Sense Media
What Was D-Day Weegy
Helloid Worthington Login
Urban Dictionary Fov
Cincinnati Bearcats roll to 66-13 win over Eastern Kentucky in season-opener
Slushy Beer Strain
Healing Guide Dragonflight 10.2.7 Wow Warring Dueling Guide
6001 Canadian Ct Orlando Fl
Elizabethtown Mesothelioma Legal Question
Overton Funeral Home Waterloo Iowa
Cvb Location Code Lookup
Dtab Customs
Site : Storagealamogordo.com Easy Call
Rural King Credit Card Minimum Credit Score
/Www.usps.com/International/Passports.htm
Jeff Now Phone Number
BMW K1600GT (2017-on) Review | Speed, Specs & Prices
Wisconsin Volleyball Team Boobs Uncensored
Living Shard Calamity
Mineral Wells Skyward
Meridian Owners Forum
Milwaukee Nickname Crossword Clue
Lindy Kendra Scott Obituary
The Procurement Acronyms And Abbreviations That You Need To Know Short Forms Used In Procurement
The Bold and the Beautiful
Gyeon Jahee
Craigslist Albany Ny Garage Sales
To Give A Guarantee Promise Figgerits
Whitehall Preparatory And Fitness Academy Calendar
USB C 3HDMI Dock UCN3278 (12 in 1)
Aita For Announcing My Pregnancy At My Sil Wedding
Thothd Download
Best Haircut Shop Near Me
Hillsborough County Florida Recorder Of Deeds
Noga Funeral Home Obituaries
2294141287
Craigslist Chautauqua Ny
Congruent Triangles Coloring Activity Dinosaur Answer Key
Read Love in Orbit - Chapter 2 - Page 974 | MangaBuddy
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated:

Views: 6029

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.