我正在尝试连接到Bitbucket服务器。我的机器有Windows,有Git Bash。
在/h/.ssh/id_rsa
和/h/.ssh/id_rsa.pub
上,我有一个存储库的密钥。
同样在/h/.ssh/config
中,我有存储库的配置:
Host my-repo-name
User my-user
Hostname my-repo.com
Port 7999
IdentityFile id_rsa
当我尝试连接到这样的存储库时:
ssh -Tv git@my-repo.com
我收到了这条消息:
OpenSSH_7.1p2, OpenSSL 1.0.2h 3 May 2016
debug1: Reading configuration data /h//.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to my-repo.com port 22.
debug1: Connection established.
debug1: identity file /h/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
我有两件事我不明白:
1.如果我有/h/.ssh/id_rsa
和/h/.ssh/id_rsa.pub
,为什么我会key_load_public: No such file or directory
?
2.如果在配置中我指定Port 7999
,为什么它连接到端口22 Connecting to my-repo.com port 22
?
答案 0 :(得分:1)
- 如果我有/h/.ssh/id_rsa和/h/.ssh/id_rsa.pub,为什么我得到key_load_public:没有这样的文件或目录?
醇>
这只是虚假的警告。如果您使用更详细的日志级别-vvv
运行,则可以找到更多信息。
- 如果在配置中我指定了端口7999,为什么它连接到端口22连接到my-repo.com端口22?
醇>
因为Port 7999
仅针对主机my-repo-name
进行了分类,而不是针对您尝试连接的my-repo.com
。如果你要运行它会被使用
ssh -Tv git@my-repo-name
答案 1 :(得分:0)
就我而言,我尝试克隆一个 gitlab 项目,该解决方案应该适用于任何 git 服务。错误是
#15 0.589 debug1: identity file /root/.ssh/id_rsa type -1,
#15 0.589 debug1: key_load_public: No such file or directory
使用后就消失了
echo "Host *\n User git\n HostName gitlab.com\n AddKeysToAgent yes\n IdentityFile /root/.ssh/id_rsa" >> /etc/ssh/ssh_config
这也是您的消息块中要求的内容:
debug1: Reading configuration data /etc/ssh/ssh_config
...
debug1: key_load_public: No such file or directory
解决方案证明ssh需要检查服务器为已知主机。如果您没有分配所需的已知主机,则 gitlab 服务器不受信任,这就是 the key_load_public cannot be found
的意思。是的,错误信息令人困惑。
当然,您也可以在不使用 echo
命令的情况下手动填充该 ssh_config。
我刚刚看到这也是 Server Fault 上的解决方案。