Multiple GitHub accounts on the same computer?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Managing multiple GitHub accounts on a single machine can be a necessity for developers who need to separate personal projects from work-related repositories or when contributing to projects that require different user profiles. This setup, while practical, requires careful configuration of Git and SSH keys to ensure the workflows remain streamlined and secure.
Understanding SSH and Git Configuration
SSH (Secure Shell) is a protocol used to securely access remote machines and services. GitHub utilizes SSH to securely communicate with Git repositories. Each SSH key pair includes a public and a private key. The public key is added to GitHub, enabling secure communication without exposing the private key.
Git is a version control system that tracks changes to files and coordinates work among multiple people. Configuring Git to handle multiple accounts involves setting up local repositories with email addresses and usernames tied to the respective GitHub accounts.
Setting Up SSH Keys
Each GitHub account needs to be associated with a unique SSH key pair. Here’s how you set them up:
- Generate SSH Keys: Open a terminal and generate a new SSH key pair using the command below, replacing
[email protected]with your GitHub email address. Do this for each account.
- When prompted, save the key to a unique file, for example
/home/user/.ssh/id_ed25519_github_account1. - Add SSH Keys to the SSH Agent:
- Add Public Key to GitHub: Copy the public key (
id_ed25519_github_account1.pub) and add it to your GitHub account under Settings > SSH and GPG keys.
Configuring Git
Configure Git to use the right email and username for the respective repositories tied to different GitHub accounts:
- Navigate to your Git repository directory.
- Set local Git configuration:
These settings will only apply to the specific repository.
Using Different SSH Keys
To direct Git to use the appropriate SSH key for a particular GitHub account, modify the SSH config file (~/.ssh/config). Add an entry for each account like so:
When cloning a repository for the first time, use the custom host defined in the SSH config:
This configuration directs Git to use the SSH key linked to the specified custom host github.com-account1, allowing you to manage different GitHub accounts efficiently.
Troubleshooting Common Issues
Key Permissions: If ssh-add fails, ensure your SSH key file permissions are set correctly. Only the user should have read and write permissions (chmod 600 ~/.ssh/id_ed25519_github_account1).
SSH Agent Not Running: If the SSH agent is not running, you will need to start it with eval "$(ssh-agent -s)" before adding keys with ssh-add.
Summary
This setup allows you to segregate your GitHub activities based on different accounts seamlessly. Below is a summary table of essential steps:
| Task | Command/Instruction |
| 1. Generate SSH Key | ssh-keygen -t ed25519 -C "[email protected]" |
| 2. Add the SSH Key to the agent | ssh-add ~/.ssh/id_ed25519_github_account1 |
| 3. Modify SSH Config | Add custom host configurations to ~/.ssh/config |
| 4. Git Clone using specific account | git clone [email protected]:username/repo.git |
| 5. Setting local Git user configuration | git config user.name "Your Name"
git config user.email "[email protected]" |
Using these steps ensures that your development environment supports multiple GitHub accounts without conflicts or security issues.

