当前位置:   article > 正文

Git ssh 配置多账户_git ssh服务器多账号

git ssh服务器多账号

注意:如果是 windows 需要使用 Git bash

创建私钥公钥


ssh-keygen -t <文件名称> -C “<注释内容>”

ssh-keygen -t user_1 -C “user_1” # 用户1
ssh-keygen -t user_2 -C “user_2” # 用户2

执行命令后,会在 ~/.ssh 目录下生成 user_1user_1.pub 两个文件,其中 user_1.pub 就是你的公钥
使用命令 cat ~/.ssh/user_1.pub 查看公钥
复制到 Git 仓库 ssh 配置项中

新建并配置 config 文件


在 ~/.ssh 目录下新建 config 文件,无需后缀,
往里面添加内容

# 示例用户1
Host user_1
HostName github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/user_1
  
# 示例用户2
Host user_2
HostName github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/user_2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

链接


这里以请求 https://github.com/netchx/netch.git 为例

git clone https://user_1/netchx/netch.git    # 将使用 user 1 的密钥
git clone https://user_2/netchx/netch.git    # 将使用 user 2 的密钥
  • 1
  • 2

重要!!!


在拉仓库的时候
git clone https://user_1/netchx/netch.git

会有提示,
Are you sure you want to continue connecting (yes/no/[fingerprint])?
这里一定要输入 yes
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/671332
推荐阅读
相关标签
  

闽ICP备14008679号