github多个账号免密登录与使用


github多个账号免密登录与使用

1 生成ssh密钥对

ssh-keygen -t rsa -C "abc@example.com" -f ~/.ssh/identityfile_name

-t参数指明密钥类型,-C参数指定用于识别这个密钥的注释,-f参数用于指定密钥路径和文件

2 将密钥对中的公钥添加到github

3 配置C:\Users\USERNAME\.ssh目录下config文件

1
2
3
4
Host hostname.github.com
HostName github.com
User git_usernames
IdentityFile C:/Users/57315/.ssh/identityfile_name

这里hostname随便起

4 测试和github的连接

单用户ssh连接github时,测试的命令是ssh -T git@github.com。多用户时,我们自己指定了一个Host Name来区分不同的github账号,测试连接的命令应修改为ssh -T git@hostname.github.comhostname.github.com即为我们在config文件中指定的Host。

使用ssh方式克隆该仓库中的代码时,也需要将命令git@github.com:username/repo.git修改为git@hostname.github.com:username/repo.git


Author: Yann
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source Yann !
  TOC