“多个git账号之间的切换 多个git账号指定不同的key”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
docker>Evan
(导入1个版本)
 
 
(未显示同一用户的6个中间版本)
第1行: 第1行:
  
多个git账号之间的切换 多个git账号指定不同的key
+
=pre=
 
+
<pre>
ssh可以通过-i使用指定的私钥文件,如:
+
ssh可以通过-i使用指定的私钥文件,
  
 
  ssh -i ~/mykey_rsa username@host
 
  ssh -i ~/mykey_rsa username@host
第15行: 第15行:
  
 
  ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C [email protected]
 
  ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C [email protected]
 +
然后根据提示连续回车即可在~/.ssh目录下得到id_rsa_github和id_rsa_github.pub两个文件,id_rsa_gthub.pub文件里存放的就是我们要使用的key </pre>
  
然后根据提示连续回车即可在~/.ssh目录下得到id_rsa_github和id_rsa_github.pub两个文件,id_rsa_gthub.pub文件里存放的就是我们要使用的key
+
=编辑 ~/.ssh/config,设定不同的git 服务器对应不同的key=
 +
注意  要提交到github 拉下来的时 一定要用ssh 而不是https 注意喽  不然得改一下 .git/config
  
编辑 ~/.ssh/config,设定不同的git 服务器对应不同的key
 
  
 
在本机添加
 
在本机添加
第32行: 第33行:
 
</pre>
 
</pre>
  
#建一个gitlab别名,新建的帐号使用这个别名做克隆和更新  
+
建一个gitlab别名,新建的帐号使用这个别名做克隆和更新  
 
<pre>Host 192.168.11.11
 
<pre>Host 192.168.11.11
 
   HostName 192.168.11.11
 
   HostName 192.168.11.11
第39行: 第40行:
  
 
</pre>
 
</pre>
 +
  
 
打开 [https://github.com/settings/ssh https://github.com/settings/ssh] 把pub key (id_rsa_github.pub) 添加一下
 
打开 [https://github.com/settings/ssh https://github.com/settings/ssh] 把pub key (id_rsa_github.pub) 添加一下
第46行: 第48行:
 
看到 You’ve successfully 就表示OK了
 
看到 You’ve successfully 就表示OK了
  
多个git账号之间的切换 也可以多个github 帐号 [http://memoryboxes.github.io/blog/2014/12/07/duo-ge-gitzhang-hao-zhi-jian-de-qie-huan/ http://memoryboxes.github.io/blog/2014/12/07/duo-ge-gitzhang-hao-zhi-jian-de-qie-huan/]
+
  ssh-keygen -t rsa -f ~/.ssh/id_rsa_evan -C [email protected]
 +
 
 +
=see also=
 +
[https://www.jianshu.com/p/b26db0a031dc 更好的管理你的git SSH-Key]
  
命令行下的git配置问题: 多个sshkey, 多个用户身份, git alias [http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/ http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/]
 
  
Git Config 命令查看配置文件 [https://cnbin.github.io/blog/2015/06/19/git-config-ming-ling-cha-kan-pei-zhi-wen-jian/ https://cnbin.github.io/blog/2015/06/19/git-config-ming-ling-cha-kan-pei-zhi-wen-jian/]
+
[http://memoryboxes.github.io/blog/2014/12/07/duo-ge-gitzhang-hao-zhi-jian-de-qie-huan/ http://memoryboxes.github.io/blog/2014/12/07/duo-ge-gitzhang-hao-zhi-jian-de-qie-huan/ 多个git账号之间的切换 也可以多个github 帐号 ]
 +
 
 +
[http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/ http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/ 命令行下的git配置问题: 多个sshkey, 多个用户身份, git alias]
 +
 
 +
[https://cnbin.github.io/blog/2015/06/19/git-config-ming-ling-cha-kan-pei-zhi-wen-jian/ https://cnbin.github.io/blog/2015/06/19/git-config-ming-ling-cha-kan-pei-zhi-wen-jian/ Git Config 命令查看配置文件 ]
 +
 
  
ssh-keygen -t rsa -f ~/.ssh/id_rsa_evan -C [email protected]
 
  
 
[https://www.linuxchina.net/?p=3393 https://www.linuxchina.net/?p=3393]
 
[https://www.linuxchina.net/?p=3393 https://www.linuxchina.net/?p=3393]
  
&nbsp;
 
 
&nbsp;
 
  
 
[[Category:git]]
 
[[Category:git]]

2021年9月17日 (五) 02:23的最新版本

pre

ssh可以通过-i使用指定的私钥文件,

 ssh -i ~/mykey_rsa username@host

但是走ssh协议的git却没有类似的参数可以指定,只能是使用用户默认的ssh私钥。

而git 一般也是用key认证的,如果你来我一样的情形 ,怎么办 ? 先假设我有两个账号,一个是github上的,一个是公司gitlab上面的。先为不同的账号生成不同的ssh-key

 ssh-keygen  -t rsa -f ~/.ssh/id_rsa_work -C [email protected]

然后根据提示连续回车即可在~/.ssh目录下得到id_rsa_work和id_rsa_work.pub两个文件,id_rsa_work.pub文件里存放的就是我们要使用的key

 ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C [email protected]
然后根据提示连续回车即可在~/.ssh目录下得到id_rsa_github和id_rsa_github.pub两个文件,id_rsa_gthub.pub文件里存放的就是我们要使用的key 

编辑 ~/.ssh/config,设定不同的git 服务器对应不同的key

注意  要提交到github 拉下来的时 一定要用ssh 而不是https 注意喽   不然得改一下 .git/config


在本机添加

cat ~/.ssh/config

Host github.com
  hostname github.com
  User git
  #port 22
  IdentityFile /home/evan/.ssh/id_rsa_github
  IdentitiesOnly yes
  

建一个gitlab别名,新建的帐号使用这个别名做克隆和更新

Host 192.168.11.11
  HostName 192.168.11.11
  User work
  IdentityFile ~/.ssh/id_rsa_work


打开 https://github.com/settings/ssh 把pub key (id_rsa_github.pub) 添加一下

ssh -vT [email protected]

看到 You’ve successfully 就表示OK了

 ssh-keygen -t rsa -f ~/.ssh/id_rsa_evan -C [email protected]

see also

更好的管理你的git SSH-Key


http://memoryboxes.github.io/blog/2014/12/07/duo-ge-gitzhang-hao-zhi-jian-de-qie-huan/ 多个git账号之间的切换 也可以多个github 帐号

http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/ 命令行下的git配置问题: 多个sshkey, 多个用户身份, git alias

https://cnbin.github.io/blog/2015/06/19/git-config-ming-ling-cha-kan-pei-zhi-wen-jian/ Git Config 命令查看配置文件


https://www.linuxchina.net/?p=3393