IDE 切换 github 账号

  1. 生成两个ssh密钥对

    • 第一个密钥对
      ssh-keygen -t rsa -C "your_first_email@example.com"
      以上指令会在用户目录下的.ssh文件夹中生成这两个文件:id_rsa和id_rsa.pub。其中,id_rsa是私钥,id_rsa.pub是公钥,需要配置到github上面

    • 第二个密钥对
      ssh-keygen -t rsa -f ~/.ssh/id_rsa_personal -C "personal_email@example.com"
      为了与第一次生成的密钥进行区分,这里我们在命令中增加了-f 参数来指定密钥名称
      同样会生成对应的公钥和私钥

    • 注意:在.ssh目录下,‌执行ssh-add id_rsa命令将秘钥添加到SSH代理中。‌如果遇到“Could not open a connection to your authentication agent”的错误,‌先执行ssh-agent bash命令启动SSH代理,‌然后再执行ssh-add id_rsa

  2. 在GitHub或其他托管平台上,分别将两个公钥(即以.pub为后缀的文件)添加到相应账号的SSH密钥中。登录到你的账号,在设置中找到SSH and GPG keys,添加新的SSH密钥。

  3. 配置ssh 用于指定不同账号对应的密钥
    在本地的~/.ssh/目录下创建一个配置文件 config

    • 第一个账号
      Host github.com
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa

    • 第二个账号
      Host github-personal
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa_udo
      “`
      注意将`IdentityFile`的值设置为你生成的密钥文件名。

  4. 测试切换是否成功

    • ssh -T git@github.com
    • ssh -T git@github-personal

posted on   朝朝暮Mu  阅读(33)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示