Basic authentication is the use of
password for authentication. For sometime Github will accept Basic authentication, the use of
password, to access repositories on Github - to clone, push and pull. The Basic authentication will be deprecated very soon this year, 2021.
Github also allows:
- Username and password with two-factor authentication
- Personal access token (PAT)
- SSH key
The PAT can only be used over HTTPS Git operations
- On Github, signup if you don't have an account or login if you already do have one
- At the top right corner, click on your
avatarand click on
Settingsfrom the drop-down
- On the left side of your
Setting Profilepage, click on
- Click on
Personal access tokenon the next page
- At the right, click on
- Give the token a name or description and check some privileges you want to give to the token
Generate token, a green button at the bottom of the page
- Copy the token and save it somewhere safely (It will still be there when you check it)
- If the token is forgotten or you could not save it, regenerate it.
vscode is my go-to text editor for my all-round development. Entering the
token every time is a nuisance. We would add the
token globally to git. For a specific application, we can add the token locally. The
token would be used as the password.
git config --global credential.helper store
- Now clone, push or pull with
tokeninstead of the
- For the sake of testing, let's create a dummy repo on Github. Choose the default settings. (Do not close the page or the browser)
- I am on ubuntu so I will install ssh on ubuntu.
- Update and install
sudo apt updatethen
sudo apt install openssh-server
sudo systemctl status sshto check the
sshstatus then hit
qto get back to the terminal
sudo ufw allow ssh, will open the
sshport. This enables us to connect to our Ubuntu system via SSH from any remote machine.
sudo systemctl disable --now sshto disable
sudo systemctl enable --now sshto enable
ssh-keygen -t ed25519 -C "firstname.lastname@example.org".
- Hit enter to use the default settings for the file name/path to save your key
- Enter and hit enter for the passphrase and reenter the passphrase and hit enter again
- Start the
ssh-agentin the background to add add key to
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519then enter the passphrase used initially to add key to client
- We can now add the ssh public key to Github. We can cat the public key then copy it or open the public key in a text editor and then copy it.
gedit ~/.ssh/id_ed25519.pubwill open the public key in gedit. Copy it.
- On Github just as we did for the toke, go to the top right corner of the page and click on the avatar
- Click on
Settingson the drop-down
- Click on
SSH and GPG keys
New SSH keyor
Add SSH key.
- add a
titleand then paste the
public keyfrom the text editor into the
- Then click on
add SSH Keyand we are done adding ssh key to Github
- The dummy repo we created earlier would have a URL,
https://github.com/username/dummyrepo.gitif we were to use HTTPS but for the SSH,
- Let's clone the project from Github using SSH,
git clone email@example.com:username/dummyrepo.git
cd dummyrepoand then
echo "# dummyrepo" >> README.md
git add README.mdand
git commit -m "README.md"to add and commit the
git push origin mainto push the committed code.
Say you have the repo already using HTTPS then you have to change the URL on your local server.
- HTTPS url:
- SSH url:
check the git url,
git remote -vwhich will display
origin https://github.com/username/dummyrepo.git (fetch)
origin https://github.com/username/dummyrepo.git (push)
to change from HTTPS to SSH,
git remote set-url firstname.lastname@example.org:username/dummyrepo.git
check the git url verify the changes,
git remote -v
origin email@example.com:username/dummyrepo.git (fetch)
origin firstname.lastname@example.org:username/dummyrepo.git (push)