Lets say you have a private/public key pair that you use to login to your server via SSH and you lose the public key, either it was deleted or corrupt and you don’t want to have to regenerate a new pair what options do you have? In this post I will demonstrate how to regenerate a public key from the corresponding private key that you still have.
- Generate Public Key From Private Ssh-keygen
- Generate Public Key From Private
- Create Public And Private Key
- Secret Key
- Generate Public Key From Private
- Generate Public Key From Private Key
Generate public key and store into a file
In cryptocurrencies, a private key allows a user to gain access to their wallet. The person who holds the private key fully controls the coins in that wallet. For this reason, you should keep it secret. And if you really want to generate the key yourself, it makes sense to generate it in a secure way. Here, I will provide an introduction to private keys and show you how you can generate your.
It is a simple one liner command to generate a public key from a private key, so lets say our private key is named ‘[email protected]’ and we want to generate the public key and name it ‘authorized_keys’. Below is the command to do this.
2 4 6 | user@workstation:~$rsync-avz--remove-source-files authorized_keys user@remote_server_ip_address:/home/user/.ssh/authorized_keys test sent95bytes received43bytes92.00bytes/sec user@workstation:~$ |
At this point our public key file is on our server where it is supposed to be in our users ‘.ssh’ directory.
Set proper permissions for public key
Lastly we will need to make sure our permissions are set properly on our public key to prevent anyone else tampering with it. We should give our key file RW, R, R permissions, below is the command to properly set permission on the key.
Generate Public Key From Private
2 | user@server:~$chmod644/home/user/.ssh/authorized_keys |
Generate Public Key From Private Key
At this point we are all set to begin using our private key to login to our server again. If you have any questions about this post please leave a comment below and if this helped you at all please share it on social media!