git命令怎么使用tortoise git已经生成的秘钥(windows)

习惯了使用Tortoise git,突然想用一下git 原生命令,发现git pull执行失败

Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

原因是没有配置ssh秘钥,那可以共用tortoise git的秘钥吗,答案是:可以

Step1:创建文件夹 C:\Users\{yourName}\.ssh

Step2: tortoise git使用的是ppk方式生成的秘钥,我们需要使用tortoise git下的puttygen工具转换秘钥

找到ppk文件,在Conversions菜单下的 Export SSH Key
保存私钥到.ssh目录下文件名为id_rsa
保存公钥(save public key)到.ssh目录下名为id_rsa.pub

Step3: 新建config文件,配置你的git源信息

# 域名地址的别名
Host xxx
    # 这个是真实的域名地址
    Hostname git@xxx.com
    # 配置使用用户名
    User yourUserName
    # 这里是id_rsa的目录位置
    IdentityFile ~/.ssh/id_rsa
    # 默认是22,如果是其他端口,一定要配置
    Port 2222

以上就完成了ssh 秘钥重用,可以使用ssh -T git@xxx.com命令验证

当然你有多个git源或者已经有了id_rsa时,可以将对应的名字修改为其他名称即可,修改包括三处:两个文件名(公钥和私钥)以及config里的IdentityFile 名称

posted on 2021-06-29 21:41  就让往事都随风  阅读(320)  评论(0编辑  收藏  举报