关于ssh:返回码22,致命:git-http-push-failed

return code 22, fatal: git-http-push-failed

我使用git init --bare在服务器上创建了自己的git repo。我在那里添加了一些文件,然后通过git clone http://www.example.com/mygit/repo从myserver克隆了我的仓库,并且克隆得很完美。现在,我想按git push origin master推送此目录,但它返回代码22。我也将PC的ssh公钥添加到http://www.example.com/mygit/repo/.ssh/authorized_keys,但仍然无法推送到我的存储库中。


仅供参考,因为在搜索" git-http-push失败的返回码22 "时,在Google上排名很高:

在服务器上使用https git和htpasswd时,似乎发送的用户名包括域:[email protected],但是期望的名称仅为user

对我来说,解决方案是在~/.netrc中添加它:

machine host.domain.tld
login the_user_name
password the_password


尝试将其添加到裸存储库中的配置文件中:

1
2
[http]
       receivepack = true


/repo/.ssh/authorized_keys对服务器上的ssh守护进程没有任何意义:sshd将在进行ssh查询的用户的家下面查找该文件:/home/user/.ssh/authorized_key

此外,如果您使用的是https:// ...网址,则无论如何都不会使用ssh。为了使ssh url正常工作,您需要正确配置Apache服务器以调用git-http-backend脚本。
例如,请参阅此git-http-backend问题。


对我来说,诀窍是启用WebDAV

我将其放在LocationMatch中:

1
2
3
4
5
6
7
 <LocationMatch /git/.*\\.git>
   Dav On
   AuthType Basic
   AuthName"Git Verification"
   AuthUserFile /etc/httpd/git/test.passwd
   Require valid-user
 </LocationMatch>

这是因为您是使用http网址而不是Github上的ssh网址进行克隆的。
现在,您正在尝试使用无法使用的ssh进行推送。
在这种情况下,git clone或git pull起作用,但git push失败。

一种解决方案是使用ssh url克隆,其格式为[email protected]:username / repo-name.git
单击"您可以使用HTTPS,SSH或Subversion \\进行克隆"消息中的SSH时,您可以在GitHub仓库上找到此URL。
然后进行更改并执行git push。确保您的机器的公共密钥在您的Github帐户中。

当前情况的另一种工作方式是在执行Git推送时提供用户名和密码。