In the toolset configuration we’ll be using, our IDE (IntelliJ IDEA) will be communicating with GitHub via SSH (“secure shell”); we’ll also be communicating with GitHub via SSH from a command line. To do this, we need a private key that can be used to encrypt data, and GitHub needs a matching public key. In this environment preparation step, you’ll generate that pair of keys, and then copy the public key to your GitHub account.

Video

Instructions

  1. In a terminal window (on Windows, use Git Bash), run the following command, substituting your e-mail address (the one you’re using in your GitHub account) for the {email} placeholder.

     ssh-keygen -t ed25519 -C "{email}"
    

    This command instructs the ssh-keygen program (part of OpenSSH) to generate a public-private key pair, using the Edwards-curve digital signature algorithm, for SSH communication.

    You will be asked for a passphrase; we recommend that you do provide a passphrase at this point, rather than leaving this option blank. (If you do provide a passphrase, you will be asked to type it again to confirm.) Please note that the characters you type for a passphrase will not be echoed to the screen. Also note that there is no way to extract this passphrase from the generated private key if you forget it. (If you do forget it, all is not lost—but you will have to through this process again.)

    After the key pair is generated, ssh-keygen will ask in what directory the key pair should be stored, and under what name. You should leave the default, which will create id_ed25519 (and id_ed25519.pub) in the .ssh subdirectory of your user directory (C:\Users\{User Name}\ on Windows, /users/{User Name}/ on Linux and OS X).

  2. Copy the contents of the public key to the clipboard.

    In Git Bash on Windows, the easiest way to do this is to type the command

     clip < ~/.ssh/id_ed25519.pub
    

    On OS X, the equivalent is the pbcopy command:

     pbcopy < ~/.ssh/id_ed25519.pub
    

    Unfortunately, neither of these commands is available by default in Ubuntu; there are equivalents that can be installed, but assuming you don’t have one of those already, simply use the cat command to copy the file contents to the terminal window:

     cat ~/.ssh/id_ed25519.pub
    

    Then, select all of the contents (starting with the text ssh-rsa and ending with the text you provided as the comment to the ssh-keygen command), and copy it to the clipboard.

  3. In your browser, navigate to github.com, and log in to your account.

  4. Under the user menu in the upper-right select the Settings command.

  5. In the Personal Settings list on the left of the browser window, click the SSH and GPG keys link.

  6. Click the New SSH key button.

  7. In the Title field, type a title for the key (this is used just for informational purposes, to help you distinguish between multiple keys).

  8. In the Key field, paste the clipboard contents.

  9. Click the Add SSH key button to save the public key in your GitHub accounts.