How To Add Git Credentials On Linux and macOS Hosts (SSH and PAT)

This post is going to be a very short guide on creating/adding a PAT (personal access token) or SSH key on GitHub and adding it to a Linux (or Mac) host.

This is necessary because GitHub has deprecated password authentication as of August 13, 2021

This means all authentication on the platform can only be done two ways:

  1. SSH/GPG Keys
  2. PAT (Personal Access Tokens)

Generating SSH Keys

Follow this guide to create ssh keys with ssh-keygen.

After that, you should have a public ssh key somewhere in your ~/.ssh/ directory.

In GitHub settings go under “SSH and GPG keys” -> “SSH Keys” -> “New SSH key”.

Now you can take that public key you just generated ( by default) and copy paste the contents into key section on GitHub - don’t forget to give it a descriptive title, hit “Add SSH key” and that’s it!

From here, you just have to remember to use SSH instead of HTTPS when cloning, pulling or pushing repos.


# do this
git clone

# instead of this
git clone

If you do want to continue to use HTTPS, you will need to generate a PAT on GitHub.

Generating a GitHub PAT (Personal Access Token)

Visit this link to get a guide on creating a PAT from your GitHub account.


Direct Link:

After the token is created with all the permissions desired (you probably want read/write acces to repos), go ahead and copy that sucker straight to your clipboard (seriously, it will disappear).

Also Note: This token is the equivalent to your GitHub password, so be careful and don’t hand it out to strangers!

Storing git credentials

By default, git credentials can be stored in ~/.git-credentials or $XDG_CONFIG_HOME/git/credentials

The schema to use in this file is as follows:



There are several other more secure ways to store or input git credentials temporarily, such as git-credential-cache, which will put your credentials in memory for a set amount of time.

Man Pages

See man gitcredentials for more info on ways to handle passing credentials to git. See man git-credential-store for more info on storing git credentials. See man git-credential-cache for more info on caching git credentials.