Git Authentication For Github
You have two options: https or ssh. You can also use both. I recommend https, because the Permissions can be fine-grained with expiration date. In both cases, following this tutorial, the credentials will be unencrypted in your home directory. If you are using a modern IDE, consider using a plug-in for GitHub. If you are using VSCode, consider using their integrated GitHub Cloning, which makes the beyond consideration obsolete.
https
Advantages
- more features provided by GitHub
- works like a password, no ‘deeper’ understanding necessary
- generated by git provider, no extra tool needed
Usage
Head over to GitHub Token Generator and generate a token. Afterwards execute these lines in your termine:
export GITHUB_TOKEN=ghp_y0ur63ner4ted9er5ona14cce5570ken#3r3
git config --add --global url."https://api:$GITHUB_TOKEN@github.com/".insteadOf "https://github.com/"
Force Usage
execute these lines in your terminal:
git config --add --global url."https://api:$GITHUB_TOKEN@github.com/".insteadOf "ssh://git@github.com:"
git config --add --global url."https://api:$GITHUB_TOKEN@github.com/".insteadOf "ssh://git@github.com/"
git config --add --global url."https://api:$GITHUB_TOKEN@github.com/".insteadOf "git@github.com:"`
git config --add --global url."https://api:$GITHUB_TOKEN@github.com/".insteadOf "git@github.com/"
Caution
The Token will be saved in plain text format in ~/.gitconfig
-file. Whoever has access to this file, has access to you GitHub account with the rights set during Token Generation.
ssh
Advantages
- one configured private-public-key-pair can authenticate every git provider and beyond that
Usage
- enter
ssh-keygen
into your terminal and follow the steps - enter
ssh-add -L
into your terminal and copy the output - add the copied key into Github SSH add Page
Force Usage
git config --global url."git@github.com:".insteadOf "https://github.com/"
Caution
The Private Key is stored in the ~/.ssh
folder. Whoever has access to this folder has the right to push/pull code to/from github as your github user. You can set a password during Key Pair creation to prevent this.