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.
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.
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.
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:
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.
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.
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.
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.
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).
Key Security: SSH keys should be handled securely. Passphrases can be set for added security to protect private keys.
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.
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.
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.
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.
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.
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.
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.
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. ...
Run ssh-keygen to generate an SSH key-pair. ...
Retrieve the public key file. ...
Start a transfer using public key authentication with the ascp command.
Start the PuTTYgen utility, by double-clicking on its .exe file.
For Type of key to generate, select RSA.
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. ...
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.
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.
We notice you're using an ad blocker
Without advertising income, we can't keep making this site awesome for you.