No-SSH approach for GitHub under Linux
I wanted to make full use of my
git repositories on GitHub without having to set up SSH access. I’m using Ubuntu Linux under WSL.
- Use GitHub web interface to create a new personal access token with the scopes
gist. Copy the token value into the clipboard as it won’t be displayed more than once.
On the local Linux host, configure
gitto store authentication information:
[~]$ git config --global credential.helper store
~/.git-credentialsto include the following line, with
USERbeing your GitHub username and
TOKENthe value of the token in the clipboard.
- Make sure the credentials file is readable only by yourself:
[~]$ chmod 400 .git-credentials
The following is a test I’ve conducted after setting up access as described in the previous section.
Clone a private repository:
$ git clone https://github.com/olliefr/memes Cloning into 'memes'... remote: Enumerating objects: 111, done. remote: Counting objects: 100% (111/111), done. remote: Compressing objects: 100% (103/103), done. remote: Total 111 (delta 18), reused 97 (delta 7), pack-reused 0 Receiving objects: 100% (111/111), 5.05 MiB | 7.54 MiB/s, done. Resolving deltas: 100% (18/18), done.
Update a file…
Push the changes to GitHub:
$ git push origin master Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 12 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 335 bytes | 335.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), completed with 1 local object. To https://github.com/olliefr/memes.git ae27d9c..c75a43e master -> master
- I picked up the idea for this worklow from the Pro Git chapter Credential Storage.
Relevant GitHub documentation pages:
- Which remote URL should I use? — convince yourself you don’t need SSH.
- About authentication to GitHub
- Creating a personal access token
Note, that now there is also official GitHub CLI, which has
auth command. It probably sets up Git configuration as well. I need to test this out and update this document.