背景

由于想测试一下 SSH Key 创建的路径(.ssh 目录路径)对于不同位置 git 项目是否有效。

比如,.ssh 默认在 C:\[users]\[username] 目录下,而项目 project 在 D:\ 目录。测试结果是依然有效,即 .ssh 在 C:\[users]\[username] 目录下时,在其他位置 push 时无需进行密码认证(测试时项目以 SSH clone)。

PS:测试前已经将远程仓库托管平台公钥配置好。

事件1(file to save the key)

在本地创建 SSH Key 过程中:

$ ssh-keygen -t rsa -C"email@xxx.xxx"

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/[usrname]/.ssh/id_rsa):

当在后面输入其它路径时发现不能键入.ssh,唯独默认路径中可包含 .ssh。不过只要路径中不包括 .xxx 即可生成  SSH Key。

事件2(the authenticity of host...)

首次 clone(SSH)时报错

关于 git 本地创建 SSH Key 遇到的一点问题(①file to save the key & ②the authenticity of host...)

 

The authenticity of host 'gitee.com (xxx.xxx.xxx.xxx)' can't be established.
ECDSA key fingerprint is xxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com,xxx.xxx.xxx.xxx' (ECDSA) to the list of known hosts.
Bad packet length 2650498063.
ssh_dispatch_run_fatal: Connection to xxx.xxx.xxx.xxx port 22: message authentication code incorrect
fatal: Could not read from remote repository.

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

事件2原因

当你第一次使用Git的clone或者push命令连接GitHub时,会得到一个警告:

The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.

RSA key fingerprint is xx.xx.xx.xx.xx.

Are you sure you want to continue connecting (yes/no)?

 这是因为Git使用SSH连接,而SSH连接在第一次验证GitHub服务器的Key时,需要你确认GitHub的Key的指纹信息是否真的来自GitHub的服务器,输入yes回车即可。

Git会输出一个警告,告诉你已经把GitHub的Key添加到本机的一个信任列表里了:

Warning: Permanently added 'github.com' (RSA) to the list of known hosts.

这个警告只会出现一次,后面的操作就不会有任何警告了。

原因参考: 廖雪峰的官方网站-GIT-添加远程仓库

相关文章:

  • 2022-12-23
  • 2021-09-12
  • 2021-09-05
  • 2022-12-23
  • 2022-03-11
  • 2022-12-23
猜你喜欢
  • 2021-09-09
  • 2021-09-18
  • 2022-12-23
  • 2021-06-16
  • 2022-01-15
  • 2022-01-14
相关资源
相似解决方案