Install command: sudo apt install git -y
- Set your username:
git config --global user.name 'your username here'
- Set your email address:
git config --global user.email 'your email here'
-
Generate an ssh key:
ssh-keygen -t ed25519 -C "your_email@example.com"
This creates a new SSH key, using the provided email as a label. When you’re prompted to:"Enter a file in which to save the key,"
press Enter. This accepts the default file location. At the prompt, to type a secure passphrase, press enter for no passphrase. If you want to use a passphrase, go ahead as it provides an extra layer of security. However, for this course you do not need to add a passphase. -
Use the following command to see your public ssh key:
cat ~/.ssh/id_ed25519.pub
copy the entire output of this command to the clipboard. See examle here: -
In your github page, go to
settings
>SSH and GPG Keys
Here add your ssh key that you copied to the clipboad in the step prior. Typeyes
(the whole word) and press enter and you are done -
Test you ssh connection by using this command:
ssh -T git@github.com
You will see the following outcome:
If you do not see an error message or a different message than the one shown prior, then your SSH connection is correct. Now you can push and clone using SSH.
important
!!! After setting up 2 Factor Authentication on GitHub, I couldn’t push my remote repositories from the command line anymore.
!!! When I tried to push a remote repo, the command line threw this error:
~ :> git push origin my-branch
Username for '[https://github.com](https://github.com/)':
myusernamePassword for '[https://myusername@github.com':](https://ginnyfahs@github.com'/)
mypasswordremote: Invalid username or password.fatal: Authentication failed for '[https://github.com/my-repository](https://github.com/repository-name)’
The error stumped me — and made me vow that, when I did ultimately get to the bottom of it, I’d do my best to pay the knowledge forward.
Command line authentication requires a personal access token.
Go to Settings:
Then Developer Settings:
Then Personal access tokens >> Tokens (classic):
Generate a new Personal Access Token (also classic). Make sure you copy the Personal Access Token as soon as it gets generated — you won’t be able to see it again!
Paste the Personal Access Token into the “Password” field when you authenticate via the command line.