Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Part 1: Configure Git

  1. In the Terminal, temporarily store your email address as a variable.
     export EMAIL="<email address>"
    
  2. Configure git with your name and email address.
     git config --global user.name $USER
     git config --global user.email $EMAIL
    

Part 2: Creating SSH Keys

You may use an existing SSH key if you already have one. You may also use RSA keys, but ed25519 keys are more secure and efficient.

  1. Generate a new ed25519 SSH key id_github without a passphrase.
     ssh-keygen -t ed25519 -C $EMAIL -f ~/.ssh/id_github -q -N ""
    

    The ssh-keygen accepts a number of options.
    -t specifies the type of key to create.
    -C specifies a comment to help identify the key.
    -f specifies the filename of the key file.
    -q specifies quiet mode.
    -N specifies a new passphrase, which is not used in this example.

  2. The SSH agent is a program that runs in the background and stores your SSH keys. Start the SSH agent in the background.
     eval "$(ssh-agent -s)"
    
  3. Configure SSH to use the SSH key.
     ~/.ssh/config << EOF
     Host github.com
       AddKeysToAgent yes
       IdentityFile ~/.ssh/id_github
     EOF
    

    The ~/.ssh/config file is used to configure SSH.
    The Host directive specifies the host to which the configuration applies.
    The AddKeysToAgent directive specifies whether keys should be automatically added to the SSH agent.
    The UseKeychain directive specifies whether the passphrase should be stored in the keychain.
    The IdentityFile directive specifies the location of the SSH key.

  4. Add the SSH key to the SSH agent.
     ssh-add ~/.ssh/id_github
    

Part 3: Add SSH Key to GitHub account

  1. Copy the ssh public key to the clipboard.
     pbcopy < ~/.ssh/id_github.pub
    
  2. In a browser, navigate to GitHub.
  3. Click on your profile icon in the top right corner and select Settings.
GitHub Settings
  1. In the left sidebar, select SSH and GPG keys.
  2. Click on New SSH key.
  3. Enter a title for the new key.
  4. Paste the public key into the Key field.
  5. Click on Add SSH key.

More Info