Skip to content

Instantly share code, notes, and snippets.

@williamli
Forked from cybersamx/ssh-key-generation.md
Created December 5, 2018 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williamli/35888ad57740052339c7efc1d17adb58 to your computer and use it in GitHub Desktop.
Save williamli/35888ad57740052339c7efc1d17adb58 to your computer and use it in GitHub Desktop.
Generate a new SSH key pair

Mac and Linux

  • Open Terminal

  • Check if you already have a SSH keypair generated. Do the following:

    $ ls -la ~/.ssh/id_rsa*
    

    If the files exist, you already have SSH installed. IMPORTANT: But if you wish to regenerate the SSH key pair, at least back up your old SSH keys.

    $ cp ~/.ssh/id_rsa ~/.ssh/id_rsa.old  # Make a copy of the old SSH private key
    $ cp ~/.ssh/id_rsa.pub ~/.ssh/id_rsa.pub.old  # Make a copy of the old SSH public key
    
  • Generate a 4096-bit key pair - yes, use the higher bit

    $ ssh-keygen -t rsa -b 4096 -C "me@myemail.com"
    # Creates a new ssh key, using the provided email as a label
    Generating public/private rsa key pair.
    
  • Enter a file in which you want to save your keys. You can press enter and the default ~/.ssh/id_rsa will be used.

    Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
    
  • Enter a passphrase. Read Github working with SSH key passphrase articule on why you should use a passphrase and at the same time you don't have to enter the passphase everytime you use your SSH key.

    Enter passphrase (empty for no passphrase): [Type a passphrase]
    Enter same passphrase again: [Type passphrase again]
    
  • From here on your SSH key pair is generated, your SSH public key is ~/.ssh/id_rsa.pub - the one with the pub extension. BE EXTRA CAREFUL when using your ~/.ssh/id_rsa file. This is your private key, guard it properly.

Windows

  1. Install Git for Windows
  2. Open Git Bash and repeat the above instructions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment