管理Git生成多个ssh key

来源:互联网 发布:免费家庭记账软件 编辑:程序博客网 时间:2024/05/16 11:34

管理Git生成多个ssh key

转载于点击打开链接
  1. 生成两个key
    • 生成key的命令ssh-keygen -t rsa -C “Your Email Address” -f 'Your Name',-f后面给的生成key的名字,如果没有指定新的名字,那么每次ssh-keygen生成的名字相同,就会发生覆盖同名文件的情况的发生。
  2. 生成两个key后,添加到对应服务器的ssh kyes管理设置中。
  3. 本地添加私钥
    • 本地添加私钥名命令ssh-add ~/.ssh/Your Key Name,如果出现“Could not open a connection to your authentication agent”的问题,可以执行命令ssh-agent bash,再运行添加命令。另外,可用通过
      • ssh-add -l 查看私钥列表
      • ssh-add -D来清空私钥列表
  4. 修改配置文件
    1.在~/.ssh目录下新建一个config的文件
    2.添加以下内容
     # oschina Host git.oschina.net HostName git.oschina.net PreferredAuthentications publickey IdentityFile ~/.ssh/oschina # github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa
    3.一点说明
    • 以上的我采用的是oschina的码云和github的两种kye的结合体,其中每段最后的IdentityFile跟着是你自己ssh key的名字,不要搞错了。
    • 最后就是测试咯
      • oschina的测试方法 ssh -T git@git.oschina.net;成功收到的回复为“Welcome to Git@OSC,‘Your Name’ ”
      • github的测试方法 ssh -T git@github.com;成功收到的回复为”Hi ’Your Name‘ ! You’ve successfully authenticated, but GitHub does not provide shell access.“
  5. 借鉴文章
    • git 配置多个SSH-Key
    • 管理git生成的多个ssh key
原创粉丝点击