In order to securely manage multiple SSH keys and authenticate them with GitHub, it's important to follow the correct steps. Having multiple SSH keys is useful when you're using different machines or need to access different GitHub accounts. Here's a step-by-step guide on managing multiple SSH keys and authenticating them with GitHub:
ls -al ~/.ssh
C:\Users\{username}\.ssh
-rw-r--r-- 1 user 197121 419 Nov 29 2022 id_ed25519 // private key
-rw-r--r-- 1 user 197121 106 Nov 29 2022 id_ed25519.pub // public key
id_rsa.pubid_ecdsa.pub.ssh directory is located.
cd ~/.ssh
ssh-keygen -t ed25519 -C "your_email@example.com"
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
$ Enter file in which to save the key(c/users/you/.ssh/id_ed25519: "unique-key-name")
ls -al ~/.ssh
-rw-r--r-- 1 user 197121 419 Nov 29 2022 id_ed25519 // OLD private key
-rw-r--r-- 1 user 197121 106 Nov 29 2022 id_ed25519.pub // OLD public key
-rw-r--r-- 1 user 197121 419 Jul 23 2023 unique-key-name // NEW private key
-rw-r--r-- 1 user 197121 106 Jul 23 2023 unique-key-name.pub // NEW public key
.ssh directory to specify which key to use for each account, as the ssh-agent can't handle multiple keys:
config file at .ssh directory path by running:
notepad config
config file.
personal account is the previously existed account with
id_ed25519 key, you can customize the account name to fit your needs.
work account the second account with newly generated key, you will need to
distinguish Host by adding any word that stands out for you; I added work.
#personal account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
#work account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/unique-key-name
IdentitiesOnly yes
config is created properly by running:
ls -al ~/.ssh
config file saved as text file, run:
mv config.txt config
cat 'unique-key-name'.pub
git@github.com/username/repository.git
git@github.com-work/username/repository.git
work to
git@github.com-work which was customized in the config file to the Host.