git初探(三)-配置ssh密钥(windows)

git_3

windows下创建和管理ssh密钥。

1.创建ssh密钥

gitbash上执行

1
ssh-keygen -t rsa -b 4096 -C "2869775223@qq.com"

执行后三个选项

  • 文件路径及名称
  • 密码 之后使用该密钥时使用的密码,可以为空
  • 确认密码
    执行之后会在默认地址/c/Users/<user>/.ssh/id_rsa生成对应的id_rsaid_rsa.pub文件.
    setting-ssh添加密钥(id_rsa.pub文件内容)

2.管理ssh密钥

如果不做配置,默认使用/c/Users/<user>/.ssh/id_rsa这个密钥,多数情况下要同时使用不同的GIT平台

  • github
  • gitee
  • gitlab
    /c/Users/<user>/.ssh路径(也就是密钥文件所在目录)下,添加config文件(没有后缀)
1
2
3
4
5
6
7
8
9
10
Host github.com    
HostName github.com
User loyalvi
PreferredAuthentications publickey
IdentityFile /c/Users/28697/.ssh/id_rsa
Host gitee.com
HostName gitee.com
User loyalvi
PreferredAuthentications publickey
IdentityFile /c/Users/28697/.ssh/id_rsa

其中配置项为:

  • Host 别名
  • HostName 域名
  • IdentityFile密钥路径
    别名的使用:
    git@github.com:loyalvi/hexo.git改成
    git@<别名 Host>:loyalvi/hexo.git
  • 修改了别名,使用域名影不影响使用?

    git remote --help可以查看git remote命令,管理远程仓库的名称