Github and how to overcome issues with SSH setup on the command line¶
If you have set up SSH authentication with Github you may run into the issue of not being able to connect to your repo on the command line. The Github documentation primarily focuses on https authentication, but this officially ceased in 2021 and can give you issues and throw you for a loop. Sounds familiar?
Github is a great tool for managing git repositories remotely, and for version control of your projects. In general the documentation on Github is good.
Unfortunately, password authentication for access to Github repos ceased in August 2021. Yet the documentation still focuses on https authentication which can trip up new and unassuming users. https authentication now requires personal access tokens, whereas using SSH keys are more straightforward and secure, once you have it set up.
This is not meant as a tutorial on how to set up Github SSH authentication - there are many guides on the web out there. It first assumes you have:
- Checked for existing SSH keys on your machine
- Generated a new SSH key on your machine
- Added the new SSH key to your Github account
To verify that your SSH key is working:
Once you are happy with the key fingerprint you may typeyes
to the prompt, which should lead to:
This confirms that the SSH key is working correctly.
Next, set up a Github repository for your project on the Github website.
The next step is to add this remote (origin) repository (on Github) for SSH authentication to your git repo on your machine:
This tells git to pull whatever is on the remote (origin) to the main branch on your machine. If you have a different branch name, you need to change the name "main" to the name of your local branch.To avoid conflicts and issues, the next three steps are important. You need to firstly pull anything on the remote repo to avoid any conflicts:
You then need to set your user email and name with the following commands:
git config --global user.email "youremail@email.com"
git config --global user.name "yourGithubUsername"
You can check the status of files tracked by git with git status
You can add tracked files in the current directory for commit with:
And then commit them with:git push
will then push them to the remote repo, and the process is complete.
I hope this helps somebody out there.