git 通过 SSH 推送到远程存储库时出现“拒绝访问”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/913587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Access denied" when pushing to remote repository via SSH
提问by oyvindio
I am a newbie with Git and seem to have a problem with pushing to a repository over a network.
Here is what I do to recreate the problem:
我是 Git 的新手,似乎在通过网络推送到存储库时遇到问题。
这是我为重现问题所做的工作:
create a new Git repository on the computer to push to
mkdir ~/git/test.git cd !$ git --bare init
On my local computer I then create a new Git repository and add a random file to it:
mkdir test git init touch TEST git add . git commit -m "initial commit"
Then add the remote computer via:
git remote add origin ssh://[email protected]/~/git/test.git
- Then I try to push the local repository to the remote via:
git push origin master
在计算机上创建一个新的 Git 存储库以推送到
mkdir ~/git/test.git cd !$ git --bare init
然后在我的本地计算机上创建一个新的 Git 存储库并向其中添加一个随机文件:
mkdir test git init touch TEST git add . git commit -m "initial commit"
然后通过以下方式添加远程计算机:
git remote add origin ssh://[email protected]/~/git/test.git
- 然后我尝试通过以下方式将本地存储库推送到远程:
git push origin master
This is what I get when I do that:
当我这样做时,这就是我得到的:
fatal: protocol error: bad line length character <- sometimes not there
Access denied
Access denied
Access denied
Access denied
FATAL ERROR: Server sent disconnect message
type 2 (protocol error):
"Too many authentication failures for user"
I am using cygwin on an XP machine and trying to push to a unix server.
我在 XP 机器上使用 cygwin 并尝试推送到 unix 服务器。
I have also tried it between my two computers I have at home and I have the same problem, both are windows machines by the way.
我也在家里的两台电脑之间试过,我有同样的问题,顺便说一下,两台电脑都是windows机器。
I have set up passwordless login via SSH and I can ssh
no problem via: ssh [email protected]
我已经通过 SSH 设置了无密码登录,我可以ssh
通过以下方式解决:ssh [email protected]
I've been trying to figure this out for two days now, any help would be appreciated
我一直在努力解决这个问题两天了,任何帮助将不胜感激
回答by oyvindio
The issue is probably that ~ won't expand correctly when using it in a ssh URI. You would need to specify the absolute path to the git repository on the remote machine in the ssh URI, like this:
问题可能是 ~ 在 ssh URI 中使用它时不会正确扩展。您需要在 ssh URI 中指定远程计算机上 git 存储库的绝对路径,如下所示:
ssh://[email protected]/home/user/git/test.git
回答by James Andres
I was having a similar issue, but the solution turned out a little different for my situation. The error message I was getting was:
我遇到了类似的问题,但解决方案与我的情况略有不同。我收到的错误消息是:
$> git push -v unfuddle master
Pushing to [email protected]:subdomain/repo.git
Received disconnect from 174.129.246.239: 2: Too many authentication failures for git
fatal: The remote end hung up unexpectedly
I couldn't figure out what the problem was, ssh -vv didn't show anything either. I already had this text in my ~/.ssh/config
我无法弄清楚问题是什么, ssh -vv 也没有显示任何内容。我的 ~/.ssh/config 中已经有了这个文本
Host subdomain.unfuddle.com
User git
IdentityFile ~/.ssh/unfuddle-subdomain-key
The issue turned out to be that Unfuddle's SSH server is configured to deny access after a certain number of SSH keys are tried. Even though I had a specific IdentityFile set my SSH client was, for unknown reasons, trying all of my local SSH keys in sequence until Unfuddle denied access. The solution was to set the SSH "IdentitiesOnly" config option to "yes" which tell the local SSH client to only send just that one IdentityFile and no others.
事实证明,问题是 Unfuddle 的 SSH 服务器被配置为在尝试了一定数量的 SSH 密钥后拒绝访问。尽管我有一个特定的 IdentityFile 设置,但我的 SSH 客户端出于未知原因,会按顺序尝试我所有的本地 SSH 密钥,直到 Unfuddle 拒绝访问。解决方案是将 SSH“IdentitiesOnly”配置选项设置为“yes”,它告诉本地 SSH 客户端只发送一个 IdentityFile 而没有其他。
# The fixed ~/.ssh/config line
Host subdomain.unfuddle.com
User git
IdentitiesOnly yes
IdentityFile ~/.ssh/unfuddle-subdomain-key
Ref: http://railspikes.com/2010/2/1/fixing-the-heroku-too-many-authentication-failures-for-git-problem
参考:http: //railspikes.com/2010/2/1/fixing-the-heroku-too-many-authentication-failures-for-git-problem
Hopefully this helps someone.
希望这有助于某人。
James
詹姆士
回答by Denis
One more key to solve such a problem. In our case the reason was gitolite.conf file with repositiories and permissions. Someone have edited it with Windows Notepad which added BOM header to it. After this repositiory had very weird behavior when some users could but some could not write to it getting access denied messages.
解决此类问题的另一把钥匙。在我们的例子中,原因是带有存储库和权限的 gitolite.conf 文件。有人用 Windows 记事本编辑了它,其中添加了 BOM 标题。在此存储库出现非常奇怪的行为之后,一些用户可以但有些用户无法写入获取访问被拒绝的消息。
回答by Norman Ramsey
I'm not sure about your access problems, but the path in
我不确定你的访问问题,但路径
git remote add origin ssh://[email protected]/~/git/test.git
worries me. What do you get with
让我担心。你能得到什么
git remote add origin ssh://[email protected]/git/test.git
?
?
Also please show output from git push -v ...
还请显示输出 git push -v ...
回答by Ikke
回答by Thomas Leonard
In your case the problem is probably the ~ character. Use:
在您的情况下,问题可能是 ~ 字符。用:
git remote add origin [email protected]/git/test.git
However, I've also seen this problem (always on Windows client machines) when the username ("user@") part was missing, so anyone else with this problem should check that too.
但是,当用户名(“user@”)部分丢失时,我也看到了这个问题(总是在 Windows 客户端机器上),所以其他有这个问题的人也应该检查一下。