GitGuardian [8 easy steps to set up multiple git accounts — 2021]
0 1 generate a ssh key 0 6 set up your workspace
-t is the algorithm, ED25519 is recommended for Create specifics .gitconfigs for each account/ /myhome/
ssh-keygen \
security and performance
directory.
|__.gitconfig
-t ed25519 \
-C is for adding your associated email as a |__work/
-C "your_personal_email@example.com" \
comment
|__.gitconfig.work
-f ~/.ssh/<personal_key>
-f is to define a filename, helping you remember |__personal/
which key is used for which user/remote.
|__.gitconfig.pers
0 2 add a passphrase
0 7 set up your git con f igs
Add an extra layer of security: if someone gains
access to your computer, your keys will be ssh-keygen -p -f ~/.ssh/<personal_key> Tell Git which key to use with the SSH command (-i option to specify an identity file/key).
compromised unless they are attached to a To update the passphrase for your SSH key at # ~/personal/.gitconfig.pers
# ~/work/.gitconfig.work
passphrase.
any time
[user]
[user]
email = your_pers_email@example.com
email = your_pro_email@google.com
name = Your Name
name = Your Name
[github]
[github]
03 add your key to ssh-agent user = “mynickname”
user = “pro_name”
[core]
[core]
sshCommand = “ssh -i ~/.ssh/<personal_key>” sshCommand = “ssh -i ~/.ssh/<professional_key>”
Make sure the ssh-agent is running, and add your
eval "$(ssh-agent -s)" && \
key (the -K option is to store the passphrase in
ssh-add -K ~/.ssh/<personal_key> # ~/.gitconfig
your keychain, macOS only).
[includeIf “gitdir:~/personal/”] # include for all .git projects under personnal/
path = ~/personal/.gitconfig.pers
[includeIf “gitdir:~/work/”]
path = ~/work/.gitconfig.work
0 4 create a ssh con f ig [core]
excludesfile = ~/.gitignore # valid everywhere
Host is set to * for every key because we will use
Git configs to select the appropriate SSH key # ~/.ssh/config
To see a list of all config the options
man git-config
based on profiles, which will give us a bit more
flexibility .
Host *
To check your activated config options
AddKeysToAgent yes
git config --list
UseKeychain yes
IdentityFile ~/.ssh/<created_key>
0 8 R epeat f ro m 1 f or every re q uired account
05 Copy it to your vcs You are done! You can now choose to
Copy your key to your clipboard and then
paste it in GitHub, GitLab or BitBucket
macOS tr -d '\n' < ~/.ssh/<created_key>.pub | pbcopy clone your repo git clone git@<repository.domain.com>:<username>/<repo_name>.git
Linux xclip -sel clip < ~/.ssh/<created_key>.pub add your remote git remote add origin git@<repository.domain.com>:<username>/<repo_name>.git
Windows cat ~/.ssh/<created_key>.pub | clip or change it git remote set-url origin git@<repository.domain.com>:<username>/<repo_name>.git