Skip to content
Snippets Groups Projects

Generate SSH Public Key from Private Key

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by William

    If you have a ssh private key and need to get a public key for it but you no longer have the public key, you can re-generate the public key using the ssh-keygen tool.

    Edited
    gen-public-key-from-private-key 181 B
    #!/usr/bin/env bash
    
    SSH_KEY_FILE=${1}
    [ -z $SSH_KEY_FILE ] && echo "Missing required parameter SSH_KEY_FILE." && exit 1
    
    ssh-keygen -f ${SSH_KEY_FILE:?} -y > ${SSH_KEY_FILE:?}.pub
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment