84.22 Git Multiple Users and SSH Keys
20200914 Consider the scenario where you might have
multiple user accounts on a git server. Perhaps the git accounts are
ktmary on https://gitlab.com.
Also, rather than both sharing your personal public key, you want each
to have their own private/public key pairs.
First clone the remote repository:
$ git clone email@example.com:kt/mykt.git
It is a public repository so anyone can clone it but not push to it.
Configure a local git username and email address to override any global values.
$ git config user.name "K T Mary" $ git config user.email "firstname.lastname@example.org" $ git config --list
Now create a new private/public key pair to access the repository as
$ ssh-keygen -f ~/.ssh/id_rsa_ktmary_gitlab -N "" -C email@example.com $ cat ~/.ssh/id_rsa_ktmary_gitlab.pub ssh-rsa AAAAB3NzaC1...A4tHGD0= firstname.lastname@example.org
Copy the public key into SSH Keys under User Settings in gitlab. Then configure the local repository clone to use this public key.
$ git config core.sshCommand "ssh -i ~/.ssh/id_rsa_ktmary_gitlab.pub -F /dev/null"
A push should then work.
$ git push
Your donation will support ongoing development and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.