Setting up SSH for each git repository individually
A lot of people have git repositories stored not just on GitHub, but on other platforms such as Codeberg.org, GitLab, or their own self-hosted alternative.
Now, the most convenient way users can authenticate and use these platforms with git is by using SSH keys. Using the same SSH key on all platforms isn’t a problem per se, but it is better to use an SSH key for each platform individually.
Configuring git
$ git config core.sshCommand "ssh -i ~/.ssh/github_ed25519"
This will tell git to use the identity file stored in ~/.ssh/github_ed25519
.
To make it the default SSH key, pass the --global
option:
$ git config --global core.sshCommand "ssh -i ~/.ssh/github_ed25519"
Setting the remote
If you cloned the repository over HTTPS, you might want to change the remote to use the SSH address instead.
Find the remote URLs
$ git remote -v
origin https@github.com:turtureanu/knowleaks.git (fetch)
origin https@github.com:turtureanu/knowleaks.git (push)
Replace the remote URLs
$ git remote remove <remote name>
$ git remote add <remote name> <remote URL>
$ git push --set-upstream <remote name> <branch>
or with the example above:
$ git remote remove origin
$ git remote add origin ssh@github.com:turtureanu/knowleaks.git
$ git push --set-upstream origin main