How to Configure SSL for Your Multiple Git Accounts
This article will guide you through how to set up ssh keys for multiple git accounts. First of all let’s consider what the SSH key is. SSH is a protocol that can be used to connect and authenticate to remote servers and services. By using SSH keys, it is easy to connect GitHub without supplying the user name and personal access token at each visit.
Step 1 — Generate SSH keys
Initially, we have to check whether there exists any ssh keys for the accounts.
ls -al ~/.ssh
If there are no keys, the following command can be used to generate new SSH keys for every account.
ssh-keygen -t rsa -C “your_git_account_email”
Then to save the generated key file, give the default location by pressing Enter key.
Step 2 — Adding SSH keys to Git Accounts
Then we have to add generated SSH keys to the git accounts. First we have to log into the Git accounts. Then log in to all git accounts and then go to settings. There you will see “SSH and CPG keys’’. Click on it. Then click on “New SSH key”. After that you have to enter the preferred title and paste the key. Then click “Add SSH key”. Finally repeat the steps for all the accounts.
Step 3 — Register new SSH key in ssh agent
The following command can be used to start the ssh-agent.
eval “$(ssh-agent -s)”
Then add keys to ssh agent by typing
ssh-add ~/.ssh/saved_ssh_key_file_name
Step 4- Creating SSH config file
Final step is to create a config file.
cd ~/.ssh
touch config
subl -a config
After that, inside the config file, settings for all git accounts can be done as follows.
# account 1
Host github..com
HostName github..com
User git
IndeittyFile~/.ssh/saved_ssh_key_filename
# account 2
Host gitlab.com
HostName gitlab.com
User git
IndeittyFile~/.ssh/saved_ssh_key_filename
Now you can work with multiple git repositories using SSH keys.
Thank you for reading !