Generate an SSH key pair – Mac

SSH is the secure shell program for connecting to remote servers. It’s also used as a transport mechanism for Git and many other tools. Part of how SSH works is based on public key cryptography, in which you have a private key accessible only to you, and a corresponding public key that you can share with anyone.

Warning: If anything doesn’t work as shown, please get in touch with the instructor right away with the details. Precise output, error messages and screen-shots will help us diagnose the problem!
  1. In the finder, go to the Applications » Utilities folder, and open the Terminal application.

    Terminal icon

    Terminal icon

    Terminal window

    Terminal window

  2. At the terminal prompt ($), type the following command and press enter:

        ssh-keygen

    It should produce output like the following. You will have to press enter three more times: once to use the default file name, and twice to enter an empty passphrase. Your fingerprint and ID will differ from mine, of course.

    Output of ssh-keygen

    Output of ssh-keygen

  3. Now we need to tell git who you are. It will tag each change you commit with your name and email address. Enter these two commands at the terminal prompt, substituting your actual name and email between the quotes:

    git config --global user.name "YOUR FULL NAME"
    git config --global user.email "YOUR EMAIL ADDRESS"
  4. Finally, type the following command at the bash prompt:

    open -e .ssh/id_rsa.pub

    The editor window will contain ssh-rsa followed by a long code. This is your public key. Select all (⌘-A), then copy (⌘-C).

    The next step depends on which course or project you are taking.

    1. If we are using my git@liucs.net server, just paste the key into an email to , along with your course number and name. You’ll have to wait for a response from me before using your git account.

    2. If we are using GitHub, log in to https://github.com/ in your browser and select Account Settings in the upper right. Then, in the section SSH Keys, you’ll find a button Add SSH key. Paste your public key into the Key section, and give it whatever title you want. Push the green button to accept.