單電腦使用多個帳戶
同一台電腦要登入兩個 GitHub 帳號時,SSH 會預設只用一把金鑰。解法是每帳號一把金鑰,在 ~/.ssh/config 用不同 Host 別名對應,clone 時網址寫那個別名。
參考:Connecting to GitHub with SSH。
產生金鑰
每個信箱/帳號各做一次,用 -f 指定不同檔名,避免覆蓋預設的 id_ed25519:
舊版 ssh:
把對應的 .pub 貼到該 GitHub 帳號的 SSH keys。
複製公鑰:
~/.ssh/config
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_email01
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_email02
Git 會依你寫的 Host 選金鑰。測試:
clone 時用別名
該專案的 user.email 建議設成本機目錄層級(不要 --global),避免用公司信箱提交到個人儲存庫: