[ad_1]
I have multiple Git accounts one is my personal use and one is for company use. Both accounts source need to be activated from my laptop.
1st, I generated two ssh keys:
% ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/my
% ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/work
2nd, use ssh-agent
% eval "$(ssh-agent -s)"
% ssh-add --apple-use-keychain ~/.ssh/my
% ssh-add --apple-use-keychain ~/.ssh/work
3rd, Edit the SSH config
touch ~/.ssh/config
and edit contents like below:
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/my
IdentityFile ~/.ssh/work
# account of myself, [email protected]
Host my
HostName github.com
User my
IdentityFile ~/.ssh/my
# account of work, [email protected]
Host work
HostName github.com
User work
IdentityFile ~/.ssh/work
4th, Adding new SSH key to my GitHub account
as the reference: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
5th, Ensure the ssh-agent is running and loaded these two keys
% ps -e | grep ssh-agent
% ssh-add -l
256 SHA256:RnbFaLfrSIX4Al134lkjaleiur1SMIz7+OFwx5I9RHVMewwo9eq [email protected] (ED25519)
Now my question is :
After I reboot the macOS, there is only one ssh key, I must activate another ssh key for work manually by the command below:
% ssh-add ~/.ssh/work
% ssh-add -l
256 SHA256:RnbFaLfrSIX4Al134lkjaleiur1SMIz7+OFwx5I9RHVMewwo9eq [email protected] (ED25519)
256 SHA256:QEWRrqpeowiufkndliuroqijr15u30491u3ojhjkrefaosdyflk [email protected] (ED25519)
and I cannot switch to the work ssh key when I working on the work repo (like ~/workcode), but I can found the % git remove -v
response right, but got the wrong information when I run % git push
as below:
ERROR: Permission to work/Test.git denied to my.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Please tutor me how to switch to my
or work
ssh key when I working for myself or working for company.
Thank you.
[ad_2]