How To Manage Multiple GitHub account on Single Machine

Managing multiple Git accounts on a single Linux machine can be a common scenario, especially for developers who contribute to different projects or work with various organizations. Using SSH keys to authenticate with Git hosts is a secure and efficient way to manage these accounts. In this tutorial, we'll walk you through the steps to add multiple Git accounts in Linux using SSH keys.
- First locate the ssh directory
cd ~/.ssh
- Generate SSH key pair(generate ssh for each acc you want)
ssh-keygen -t ed25519 -C "youremail@github"
This command generate the ssh key pair at ~/.ssh
- Configure SSH for each github account by creating a
configfile.
touch ~/.ssh/config
- Inside the config file, add the following
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/name_of_ssh_key_generated_earlier
- For each account you want to add, repeat the steps above and change the
IdentityFileto the new ssh key generated for that account and change the host to your choice Go to github.com/settins/new/ssh and add the ssh key from the file that have
.pubextension generated for the desired accountTo test if the SSH is working, run the following command
To test if the SSH is working clone a private repo using ssh
git clone git@<custom_host_from_config>:<you_github_username>/<repo>.git
- Add alias to the cloned repo using the ssh to make it simple each time you want to push or pull
git remote add origin git@<custom_host_from_config>:<you_github_username>/<repo>.git - Add some changes to the cloned repo and push it to the remote repo and check if the changes are reflected in the remote repo



