ssh-add is a command for adding SSH private keys into the SSH authentication agent for implementing a single sign-on with SSH. The agent process is called ssh-agent;
The cool thing about ssh-agent and ssh-add is that they allow the user to use any number of servers, spread across any number of organizations, without having to type in a password whenever moving between servers. This is commonly used by system administrators to move among the machine they administer. It is also widely used in universities and research institutions for accessing computing resources.
A more practical example would be: when anyone shifts to a new organization and gets a new organization email address for the specific organization. He/She might need to create a VCS(version control system) account at GitHub, bitbucket, GitLab, etc. Most Developers already have one personal account on any of those VCS sites. So to set up these two accounts on a single machine sometimes complex. In this post we will learn how to set up two or more VCS account on a single machine.
The below command will work on Ubuntu and Mac but Windows may not. But In Windows, using the Windows subsystem (WSL) will solve the below command issue.
# With Office Email
ssh-keygen -t rsa -b 4096 -C "rezwanul.haque@vivasoftltd.com" -f rezwanul.viva
# With Personal Email
ssh-keygen -t rsa -b 4096 -C "rezwanul.cse@gmail.com" -f rezwanul-haque
touch config
vim config
# Personal account - default config
Host github.com-rezwanul-haque
HostName github.com
User git
IdentityFile ~/.ssh/rezwanul-haque
# Work account - Viva
Host github.com-rezwanul-viva
HostName github.com
User git
IdentityFile ~/.ssh/rezwanul.viva
sudo vim ~/.gitconfig
# Default account-Personal
[user]
name = rezwanul-haque
email = rezwanul.cse@gmail.com
# Professional account-Office
[includeIf "gitdir:~/<office_work_space_path>/"]
path = ~/<office_work_space_path>/.gitconfig-viva
# Professional account-organization
[user]
name = rezwanul-haque-viva
email = rezwanul.haque@vivasoftltd.com
ssh-add -D
ssh-add rezwanul-haque
ssh-add rezwanul.viva
# Check if added or not
ssh-add -l
ssh -T github.com-rezwanul-haque
ssh -T github.com-rezwanul-viva
Also read this article on our official blog
# need to add github-hostname
git clone git@<HostName>:Rezwanul-Haque-Viva/<office_project_repo>.git
Example: git clone git@github.com-rezwanul-viva:Rezwanul-Haque-Viva/<office_project_repo>.git