赞
踩
注意:如果是 windows 需要使用 Git bash
ssh-keygen -t user_1 -C “user_1” # 用户1
ssh-keygen -t user_2 -C “user_2” # 用户2
执行命令后,会在 ~/.ssh 目录下生成 user_1 和 user_1.pub 两个文件,其中 user_1.pub 就是你的公钥
使用命令 cat ~/.ssh/user_1.pub 查看公钥
复制到 Git 仓库 ssh 配置项中
在 ~/.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
这里以请求 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 的密钥
在拉仓库的时候
git clone https://user_1/netchx/netch.git
会有提示,
Are you sure you want to continue connecting (yes/no/[fingerprint])?
这里一定要输入 yes
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。