简体   繁体   English

通过SSH推送到远程存储库时,“访问被拒绝”

[英]“Access denied” when pushing to remote repository via SSH

I am a newbie with Git and seem to have a problem with pushing to a repository over a network. 我是Git的新手,似乎无法通过网络推送到存储库。
Here is what I do to recreate the problem: 这是我要解决的问题:

  1. create a new Git repository on the computer to push to 在计算机上创建一个新的Git存储库以推送到

     mkdir ~/git/test.git cd !$ git --bare init 
  2. On my local computer I then create a new Git repository and add a random file to it: 然后在本地计算机上创建一个新的Git存储库,并向其中添加一个随机文件:

     mkdir test git init touch TEST git add . git commit -m "initial commit" 
  3. Then add the remote computer via: git remote add origin ssh://user@site.com/~/git/test.git 然后通过以下方式添加远程计算机: git remote add origin ssh://user@site.com/~/git/test.git

  4. Then I try to push the local repository to the remote via: git push origin master 然后,我尝试通过以下方式将本地存储库推送到远程: 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 user@site.com 我已经通过SSH设置了无密码登录,并且可以通过ssh user@site.com ssh没问题

I've been trying to figure this out for two days now, any help would be appreciated 我已经尝试了两天,希望能对您有所帮助

The issue is probably that ~ won't expand correctly when using it in a ssh URI. 问题可能是〜在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中指定远程计算机上git存储库的绝对路径,如下所示:

ssh://user@site.com/home/user/git/test.git

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 git@subdomain.unfuddle.com: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. 我不知道是什么问题,ssh -vv也没有显示任何内容。 I already had this text in my ~/.ssh/config 我的〜/ .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. 原来的问题是,尝试了一定数量的SSH密钥后,Unfuddle的SSH服务器配置为拒绝访问。 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. 尽管我设置了特定的IdentityFile,但出于未知原因,我的SSH客户端还是按顺序尝试了所有本地SSH密钥,直到Unfuddle拒绝访问为止。 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. 解决方案是将SSH“ IdentitiesOnly”配置选项设置为“ yes”,该选项告诉本地SSH客户端仅发送一个IdentityFile,不发送其他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 詹姆士

One more key to solve such a problem. 解决这一问题的另一个关键。 In our case the reason was gitolite.conf file with repositiories and permissions. 在我们的例子中,原因是带有存储库和权限的gitolite.conf文件。 Someone have edited it with Windows Notepad which added BOM header to it. 有人使用Windows记事本对其进行了编辑,该记事本已向其中添加了BOM表头。 After this repositiory had very weird behavior when some users could but some could not write to it getting access denied messages. 此存储库具有非常怪异的行为之后,一些用户可以但有些无法写入该信息,从而获得拒绝访问的消息。

I'm not sure about your access problems, but the path in 我不确定您的访问问题,但是其中的路径

git remote add origin ssh://user@site.com/~/git/test.git

worries me. 让我担心 What do you get with 你得到什么

git remote add origin ssh://user@site.com/git/test.git

?

Also please show output from git push -v ... 还请显示git push -v ...输出git push -v ...

尝试使用

ssh://user@site.com:/home/user/git/test.git

In your case the problem is probably the ~ character. 在您的情况下,问题可能是〜字符。 Use: 采用:

  git remote add origin user@site.com/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客户端计算机上),因此其他任何有此问题的人也应该进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过SSH设置远程GIT存储库? (无代码访问远程位置) - Setup remote GIT repository via SSH? (No code access to the remote location) 通过 SSH 从远程服务器推送 git commit:权限被拒绝(公钥)。 致命:无法从远程存储库读取 - Pushing git commit from remote server through SSH: Permission denied (publickey). fatal: Could not read from remote repository 通过SSH在aptana3中使用git推送到远程 - Pushing to remote with git in aptana3 via SSH 远程匿名访问存储库被拒绝? - Remote anonymous access to repository denied? Windows Git-bash致命:无法从远程存储库读取。 当推SSH - Windows Git-bash fatal: Could not read from remote repository. when pushing through ssh 使用ssh访问bitbucket的Jenkins git插件:权限被拒绝(publickey)。 致命:无法从远程存储库读取 - Jenkins git plugin with ssh access to bitbucket: Permission denied (publickey). fatal: Could not read from remote repository 使用git推送到存储库时权限被拒绝 - Permission denied when pushing to repository with git cocoapod:将存储库推送到主干时,权限被拒绝 - cocoapod : Permission denied when pushing repository to trunk ssh上的git:拒绝存储库读取访问 - git over ssh: Repository read access denied 将文件推送到远程时权限被拒绝 - Permission denied when pushing file to remote
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM