The main purpose of setting up two or more accounts on single PC is to establish SSO (Single Sign On) between local git repository and the remote git repository to avoid the need for entering password for each git operation on remote server.
Generating SSH keys on Local PC
List all the SSH keys generated on the local PC;
$ls -la ~/.ssh
By default id_rsa and id_rsa.pub will be the keys used in ssh communication unless it is changed over the ~/.ssh/config file. And the default ssh key-pair can be generated with following command;
$ssh-keygen -t rsa -C "<email>"
t – key type
c – comment
$ssh-keygen -t rsa -C "firstname.lastname@example.org"
When executing the above command following questions will be popped expecting answers or leave blank for defaults.
File name – Enter; to generate the key on the default location which is ~/.ssh
Passphrase – Enter; if additional passcode is not needed on each remote interraction, else enter the passcode needed
Re-enter Passphrase – Enter, if no passcode used, else re-enter the passcode
This will generate public id_rsa.pub and private id_rsa keys.
For the second account, generate another key and define the key file name with -f param;
$ssh-keygen -t rsa -C "<email>" -f "<file name>"
f – file name to store the keys
$ssh-keygen -t rsa -C "email@example.com" -f "id_rsa_work_account"
Update SSH Config on Local PC
Each ssh key file has to be defined with ~/.ssh/config file in order to get them consumed over respective ssh operations.
To view the current content of the file use the following command.
And if the file does not exist, create the above file and the file format can be defiled as below;
Host <host as a profile>
HostName <exact host name to match>
User <registered user account>
IdentityFile <private key file>
Host – Remote repository name can use as a profile name
HostName – Remote repository Host name
User – Registered user account name
IdentityFile – SSH private key file
#Default account, - the default config
Adding SSH keys to the Git accounts
Copy the public key content and update it on the designated SSH Keys section within the respective remote repository.
Git – “CPG and SSH Keys”
Bitbucket – “SSH Keys”
Register SSH keys with ssh-agent on local PC
Following command register the ssh key with the SSH agent running on the local PC;
$ssh-add <private key file>
Make sure the ssh agent is running. If not start the agent with following command and try adding ssh private keys again;
Configure commit identity information
To update username and email related to commit specific to a project the following approach can be used;
$git config user.name "amie"
$git config user.email "firstname.lastname@example.org"
To define the identity information globally applicable for all the repositories configured on the local PC;
$git config --global user.name "
$git config -global user.email "