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
- In the Terminal, temporarily store your email address as a variable.
export EMAIL="<email address>"
- 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.
- 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. - 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)"
- 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.
TheHost
directive specifies the host to which the configuration applies.
TheAddKeysToAgent
directive specifies whether keys should be automatically added to the SSH agent.
TheUseKeychain
directive specifies whether the passphrase should be stored in the keychain.
TheIdentityFile
directive specifies the location of the SSH key. - Add the SSH key to the SSH agent.
ssh-add ~/.ssh/id_github
Part 3: Add SSH Key to GitHub account
- Copy the ssh public key to the clipboard.
pbcopy < ~/.ssh/id_github.pub
- In a browser, navigate to GitHub.
- Click on your profile icon in the top right corner and select Settings.
- In the left sidebar, select SSH and GPG keys.
- Click on New SSH key.
- Enter a title for the new key.
- Paste the public key into the Key field.
- Click on Add SSH key.