git push 到远程存储库“无法从远程存储库读取”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16118797/
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
git push to remote repository "Could not read from remote repository"
提问by user1090755
I searched for a while but I can't find a solution to my Problem.
我搜索了一段时间,但找不到解决我的问题的方法。
I have a Server I can connect to via ssh with the username git
and a local git repository.
Now I want to push my local repository to a newly created one on the Server.
我有一个可以使用用户名git
和本地 git 存储库通过 ssh 连接到的服务器。
现在我想将我的本地存储库推送到服务器上新创建的存储库。
Here is what I did:
这是我所做的:
- created a git repository in
/home/git/test.git
- initialized the repository as bare
- added the remote repository on the local machine
git remote add test ssh://git@serverIp:/home/git/test.git
- now I executed the push command:
git push test master
- 在其中创建了一个 git 存储库
/home/git/test.git
- 将存储库初始化为裸
- 在本地机器上添加了远程存储库
git remote add test ssh://git@serverIp:/home/git/test.git
- 现在我执行了 push 命令:
git push test master
I always get the
我总是得到
fatal: could not read from remote repository
Please make sure you have the correct access rights
and the repository exists.
I am working on a local windows 7 machine and want to upload to a linux server.
I can log in via ssh with the git
user.
I also tried to do this as the root
user(to get things to work once) with the same result.
I never get asked for the ssh password
.
我正在本地 Windows 7 机器上工作,想上传到 linux 服务器。
我可以通过 ssh 与git
用户登录。我也尝试以root
用户身份(让事情工作一次)这样做,结果相同。
我从来没有被要求提供 ssh password
。
I really don't know what I am doing wrong.
Before you call this a duplicate, I searched a lot for this problem and none seemed to talk about the same problem.
我真的不知道我做错了什么。
在你称之为重复之前,我搜索了很多这个问题,但似乎没有人谈论同样的问题。
update:
更新:
- "which git" returns /usr/bin/git
- PATH echo includes /usr/bin
- id_rsa and id_rsa.pub files are all set up and withput Passphrase
- ssh git@serverIp which git-receive-pack works too and returns /usr/bin/git-receive-pack
- ssh git@serverIp ls /home/git/test.git works
- all relevant directories are chmod 755
- git is owner of the repository
- auth.log file gets no new entries on tried push command
- GIT_TRACE=2 git push test master returns:
'C:\Program Files (x86)\PuTTY\plink.exe' '-batch' 'git@serverIp' 'git-receive-pack '\''/home/git/test.git'\''' fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
- “which git”返回/usr/bin/git
- PATH 回显包括 /usr/bin
- id_rsa 和 id_rsa.pub 文件都设置好了,没有密码
- ssh git@serverIp git-receive-pack 也可以工作并返回 /usr/bin/git-receive-pack
- ssh git@serverIp ls /home/git/test.git 工作
- 所有相关目录都是 chmod 755
- git 是存储库的所有者
- auth.log 文件在尝试推送命令时没有新条目
- GIT_TRACE=2 git push test master 返回:
'C:\Program Files (x86)\PuTTY\plink.exe' '-batch' 'git@serverIp' 'git-receive-pack '\''/home/git/test.git'\''' 致命:无法从远程存储库读取。请确保您拥有正确的访问权限并且存储库存在。
采纳答案by VonC
In this case, using openssh over putty was key.
在这种情况下,在腻子上使用 openssh 是关键。
Original answer (tips for debugging)
原始答案(调试提示)
I can log in via ssh with the
git
user.
我可以通过 ssh 与
git
用户登录。
That means this works:
这意味着这有效:
ssh git@serverIp
You do have a HOME
variable defined, and ssh public/private keys (id_rsa
/ id_rsa.pub
) in %HOME%/.ssh/
.
您确实HOME
定义了一个变量,并且 ssh 公钥/私钥 ( id_rsa
/ id_rsa.pub
) 在%HOME%/.ssh/
.
This questionsuggests a different url:
这个问题暗示了一个不同的网址:
git remote set-url test git@serverIp:/home/git/test.git
Make sure you did create your git repo as git (and not as root, when you created the git account, as in this question).ssh git@serverIp "which git"
should return the path of the git executable.
确保您确实以 git 身份创建了 git repo(而不是以 root 身份创建的,当您创建 git 帐户时,如本问题所示)。ssh git@serverIp "which git"
应该返回 git 可执行文件的路径。
Check also that all parent directories have the relevant x
(execute) bit set for the user git
or the group gitgroup
, running ls -ld /home /home/git /home/git/test.git
.
Also, getting more info for a git command can be done with:
还要检查所有父目录是否x
为用户git
或组设置了相关(执行)位gitgroup
,运行ls -ld /home /home/git /home/git/test.git
.
此外,可以通过以下方式获取 git 命令的更多信息:
git push --verbose
or:GIT_TRACE=2 git push test master
git push --verbose
或者:GIT_TRACE=2 git push test master
If you have a private ssh key with a password, it would be best to first test those ssh commands with a private ssh key notpassword-protected, to see if the issue persists.
Or, you can keep that password-protected ssh key, but double-check your .bashrc
as in this answer.
如果您有带密码的私有 ssh 密钥,最好先使用不受密码保护的私有 ssh 密钥测试这些 ssh 命令,看看问题是否仍然存在。
或者,您可以保留该受密码保护的 ssh 密钥,但请.bashrc
在此答案中仔细检查您的情况。
For any ssh connection issue (where git's password is needed), check:
对于任何 ssh 连接问题(需要 git 的密码),请检查:
/var/log/auth.log
,- an sshd debug session
/var/log/auth.log
,- 一个sshd的调试会话
In your case, since it works with ssh git@serverIp
(interactive secure shell), but not with git (which opens a non-interactive secure shell), have a look at this thread, which references this one:
根据你的情况,因为它与ssh git@serverIp
(交互式安全Shell),但不与混帐(这将打开一个非交互的安全壳),看看这个线程,其中引用这一项:
When ssh is started with a commandline, a non-interactive non-login shell is started.
However...bash
does not use$BASH_ENV
in this case, so setting it in~/.ssh/environment
(e.g. to/etc/profile
) doesn't help.
What bash does is source/etc/bashrc
and~/.bashrc
.
当使用命令行启动 ssh 时,会启动一个非交互式非登录 shell。
但是...在这种情况下bash
不使用$BASH_ENV
,因此将其设置为~/.ssh/environment
(例如 to/etc/profile
)无济于事。
bash 所做的是 source/etc/bashrc
和~/.bashrc
.
Make sure that /etc/profile
does define the path for git
, since a non-login account could be used here(that seems to be the case here, since ssh git@serverIp "which git"
worked, and ssh git@serverIp "git --version"
should too).
确保/etc/profile
确实定义了 的路径git
,因为这里可以使用非登录帐户(这里似乎是这种情况,因为ssh git@serverIp "which git"
有效,也ssh git@serverIp "git --version"
应该如此)。
But check also the right issue, and test a chmod 755
on /home
, /home/git
and /home/git/test.git
.
但也要检查正确的问题,并chmod 755
在/home
,/home/git
和上测试/home/git/test.git
。
回答by Juan Matias
You can also check your SSH identities by doing:
您还可以通过执行以下操作来检查您的 SSH 身份:
$ ssh-add -L
I had a similar problem. There was a wrong key in my identities, don't remember why. I just delete all my identities (maybe you will need to add keys again):
我有一个类似的问题。我的身份中有一个错误的密钥,不记得为什么。我只是删除了我所有的身份(也许您需要再次添加密钥):
$ ssh-add -D
Then I did push/pull without problems.
然后我没有问题地推/拉。
回答by 62mkv
I personally had 2 different issues with this:
我个人对此有两个不同的问题:
plink
(which is used by git on Windows) does not acceptid_rsa
private key as it is in OpenSSH 2 format => I had to convert it (usingputtygen
) to PuTTY own.ppk
format and attach via Git Extensions "Remotes
" dialogI specified the path to git folder wrongly, 'cause my ssh session was chrooted (It might be wrong word) and I specified that what was my FTP "
root
" as "/
", while it was "/home/www/username/
" instead.
plink
(由 Windows 上的 git 使用)不接受id_rsa
私钥,因为它是 OpenSSH 2 格式 => 我必须将它(使用puttygen
)转换为 PuTTY 自己的.ppk
格式并通过 Git 扩展“Remotes
”对话框附加我错误地指定了 git 文件夹的路径,因为我的 ssh 会话被 chroot 了(这可能是错误的词),并且我指定了我的 FTP“
root
”为“/
”,而它是“/home/www/username/
”。
I understood all this, using GIT TRACE=2
as described above and also by using procmon
to determine the exact command-line for plink
and then playing with it, adding "-v
" option ("verbose").
我理解了这一切,使用GIT TRACE=2
如上所述,还通过使用procmon
来确定确切的命令行plink
,然后使用它,添加“ -v
”选项(“详细”)。
回答by konyak
Set GIT_SSH environment variable to the full path of TortoisePlink.exe
(you may have to download TortoiseGit for this) instead of PuTTY's plink.exe
. This will allow for popup dialog window to prompt for things, i.e., confirm fingerprint, or enter password. If you use plink.exe
through Git, you cannot type in responses to plink.exe prompts, which if there are any prompts will cause the fatal error you saw.
将 GIT_SSH 环境变量设置为TortoisePlink.exe
(为此您可能需要下载 TortoiseGit)的完整路径,而不是 PuTTY 的plink.exe
. 这将允许弹出对话框窗口进行提示,即确认指纹或输入密码。如果plink.exe
通过 Git使用,则无法输入对 plink.exe 提示的响应,如果有任何提示将导致您看到的致命错误。