How to Configure Multiple GitHub Accounts with SSH on One Local Machine
Differences Between SSH and HTTPS
Security
HTTPS sends IDs and tokens (passwords) via SSL/TLS. While secure, fundamentally, they are still exposed on the network path, albeit well-wrapped.
SSH uses asymmetric keys (public key infrastructure). There is a private key and a public key; the private key stays only on your computer and is never exposed to the network. It is structurally safer than HTTPS.
To use an analogy: if HTTPS is a very strong door, SSH is having no door at all. If there is no door, there is no way to enter.
However, even SSH is not 100% secure. There is no such thing as 100% security in IT.
Convenience
With HTTPS, you have the hassle of logging in/out of GitHub when committing with different accounts.
With SSH, if you write the labels correctly in the configuration file, you can freely use multiple accounts without logging out.
GitHub SSH Configuration
1. Generate SSH Keys (Separate by Account)
Generate keys by clearly specifying the file path and name so they don't mix with existing keys.
# For Account A (specify path and filename)
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_github_A
# For Account B
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_github_BNote: You can press Enter to skip the Passphrase or include one. If included, it will ask every time you git push (can be automated to ask once via settings).
2. Write SSH Config File
Tell the computer which key (IdentityFile) to bring out depending on the connection address (Host).
# Open config file
vim ~/.ssh/config# Enter the following content (Set Host name to a convenient alias)
# Account A Settings
Host github.com-A
HostName github.com
User git
IdentityFile ~/.ssh/id_github_A
# Account B Settings
Host github-B
HostName github.com
User git
IdentityFile ~/.ssh/id_github_B3. Register Public Key on GitHub
Paste the contents of the public key (.pub) into the settings page of each account (Settings > SSH and GPG keys).
# Copy the output and register to each account
cat ~/.ssh/id_github_A.pub
cat ~/.ssh/id_github_B.pub
Caution: You must give GitHub the contents in .pub! The one without .pub is your private key.
4. Remote Address Configuration (Core)
When connecting to a repository, you must use the Host alias set in Config instead of github.com.
- Existing method:
[email protected]:User/repo.git - Multi-account method:
git@[HostAlias]:User/repo.git
# Example: When connecting with Account B
git remote set-url origin git@github-B:UserB/repo-name.gitLog
- • 2026-01-20: create