Git多用户
About 2 min
1、生成新的SSH密钥
1、生成SSH密钥,参考文档 2、将公钥配置在Github账户,参考文档
2、添加到 ssh-agent
windows
使用管理员打开power-shell
# 1、确认ssh-agent服务是否启动
get-service ssh*
# 2、如果ssh-agent为stopped,则启动,否则直接跳到第三步
# 2.1 设置ssh-agent启动方式为手动
Set-Service -Name ssh-agent -StartupType Manual
# 2.2 启动ssh-agent
Start-Service ssh-agent
# 2.3 设置ssh-agent启动方式为自动
Set-Service -Name ssh-agent -StartupType automatic
# 3、添加密钥到ssh-agent
ssh-add c:/Users/username/.ssh/id_private
# 出现Identity added: c:/Users/username/.ssh/id_private ([email protected])代表添加成功
验证一下是否配置成功
ssh -T [email protected]
Hi imarshio! You've successfully authenticated, but GitHub does not provide shell access.
# 出现上面语句则代表配置成功
# 如果出现超时可以试试如下命令
ssh -T -p 443 [email protected]
3、配置多个账户的 SSH
3.1、将多个账户的私钥添加到ssh-agent
ssh-add c:/Users/username/.ssh/id_private
3.2、更新ssh config
Windows的ssh config文件在c:\Users\demouser\.ssh
目录,
# 区分
Host github.com
HostName github.com
AddKeysToAgent yes
IgnoreUnknown UseKeychain
UseKeychain yes
IdentityFile c:/Users/shenqing/.ssh/id_marshio
Host git.deepq.tech
HostName git.deepq.tech
IgnoreUnknown UseKeychain
AddKeysToAgent yes
UseKeychain yes
IdentityFile c:/Users/shenqing/.ssh/id_rsa
TIPS https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent?platform=mac IgnoreUnknown参数只有在mac下支持。
参考
参考英文官网:https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage 参考中文官网:https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%87%AD%E8%AF%81%E5%AD%98%E5%82%A8
其他