git 即使提供了公钥,Gitosis 也需要密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/907004/
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
Gitosis requires password even though the public key is given
提问by ZelluX
I'm confronted with some problems when trying to configure gitosis on my Archlinux
尝试在我的 Archlinux 上配置 gitosis 时遇到了一些问题
http://wiki.archlinux.org/index.php/Setting_Up_Git_ACL_Using_gitosis
http://wiki.archlinux.org/index.php/Setting_Up_Git_ACL_Using_gitosis
I referred to this wiki article and successfully installed gitosis.
我参考了这篇wiki文章并成功安装了gitosis。
$ sudo pacman -U gitosis-git-20090525-1-i686.pkg.tar.gz
$ sudo -H -u gitosis gitosis-init < /tmp/id_rsa.pub
$ sudo pacman -U gitosis-git-20090525-1-i686.pkg.tar.gz
$ sudo -H -u gitosis gitosis-init < /tmp/id_rsa.pub
And modified /srv/gitosis/.ssh/authorized_keys to include my local user's id_rsa.pub.
并修改 /srv/gitosis/.ssh/authorized_keys 以包含我本地用户的 id_rsa.pub。
But when I run git clone
as the local user,
但是当我git clone
以本地用户身份运行时,
$ git clone gitosis@host:gitosis-admin.git
$ git clone gitosis@host:gitosis-admin.git
It says
它说
Initialized empty Git repository in /home/wyx/gitosis-admin/.git/
[email protected]'s password: *****
fatal: 'gitosis-admin.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
在 /home/wyx/gitosis-admin/.git/
[email protected] 中初始化空 Git 存储库的密码:*****
致命:'gitosis-admin.git' 似乎不是一个 git 存储库
致命:远端意外挂断
So the git clone operation failed. I'm wondering why it tries to initialize an empty git repository in my local user's directory (/home/wyx)? And since I've already added local user's id_rsa.pub in .ssh/authorized_keys, why does it still ask for password?
所以git clone操作失败了。我想知道为什么它会尝试在我的本地用户目录 (/home/wyx) 中初始化一个空的 git 存储库?既然我已经在 .ssh/authorized_keys 中添加了本地用户的 id_rsa.pub,为什么它仍然要求输入密码?
采纳答案by mshroyer
An empty repository was created because that's just how git works: it has to init a repo before it can start pulling remote objects into it. Unfortunately this means you'll have to manually delete the empty repo before you try cloning again.
创建了一个空的存储库,因为这就是 git 的工作方式:它必须先初始化一个存储库,然后才能开始将远程对象拉入其中。不幸的是,这意味着您必须在再次尝试克隆之前手动删除空存储库。
As for why the clone failed, it looks like you're using the wrong syntax for the remote repository path; git clone
doesn't use scp syntax. In fact, if you don't specify a clone protocol, I believe it assumes the git protocol rather than ssh, which would probably be why it asked you for a password. Try this instead:
至于为什么克隆失败,看起来你对远程存储库路径使用了错误的语法;git clone
不使用 scp 语法。事实上,如果您不指定克隆协议,我相信它假定使用 git 协议而不是 ssh,这可能就是它要求您输入密码的原因。试试这个:
$ git clone ssh://gitosis@host/~/gitosis-admin.git
回答by Rahul
I also faced the same problem "fatal: '/gitosis-admin.git' does not appear to be a valid repository." I searched a lot for the problem and finally found the solution.
我也遇到了同样的问题“致命:'/gitosis-admin.git' 似乎不是一个有效的存储库。” 我搜索了很多问题,终于找到了解决方案。
Actually, the default address of gitosis user is "/srv/gitosis" : As in case of my setup having ubuntu server 10.04.
实际上,gitosis 用户的默认地址是“/srv/gitosis”:就像我的设置有 ubuntu 服务器 10.04 一样。
And when we write "git clone [email protected]:gitosis-admin.git", it searches for gitosis-admin.git repository in /srv/gitosis. So when I entered inside the /srv/gitosis, I found out that there is another repository inside it named as repositories which consists of the gitosis-admin.git repository.
当我们写“git clone [email protected]:gitosis-admin.git”时,它会在 /srv/gitosis 中搜索 gitosis-admin.git 存储库。所以当我进入 /srv/gitosis 时,我发现里面有另一个名为 repositories 的存储库,它由 gitosis-admin.git 存储库组成。
So actually by default the gitosis-admin.git was not in the default location. So I have to modify the command path and then it worked fine.
所以实际上默认情况下 gitosis-admin.git 不在默认位置。所以我必须修改命令路径,然后它才能正常工作。
I got the repository cloned onto my local machine. I used the command as:
我将存储库克隆到我的本地机器上。我将命令用作:
"git clone [email protected]:repositories/gitosis-admin.git" and it worked fine for me.
“git clone [email protected]:repositories/gitosis-admin.git”对我来说效果很好。
See for the gitosis-admin directory in your case and I hope you will be able to solve your problem.
请参阅您的案例中的 gitosis-admin 目录,我希望您能够解决您的问题。
回答by RawMean
This is what solved the problem for me (on Ubuntu):
这就是为我解决问题的原因(在 Ubuntu 上):
git clone [email protected]:/srv/gitosis/repositories/gitosis-admin.git
回答by Shoan
Gitosis creates it's own authorized_keys
file. If you already have that file, delete it and allow gitosis-init to recreate it. Once that's done, don't mess with the file.
Gitosis 创建它自己的authorized_keys
文件。如果您已经拥有该文件,请将其删除并允许 gitosis-init 重新创建它。完成后,不要弄乱文件。
回答by bdurand
I had the same problem on ubuntu,
我在ubuntu上遇到了同样的问题,
It worked with git clone ssh://git@serverName/absolutePath/gitosis-admin.git
它与 git clone ssh://git@serverName/absolutePath/gitosis-admin.git
回答by rgulia
I resolved a similar issue. It might not be exactly what is happening in your case but you could try to re-apply the same troubleshooting which I did.
我解决了一个类似的问题。这可能与您的情况不完全相同,但您可以尝试重新应用我所做的相同故障排除。
I realized that when I was pushing keys for a new user I was getting this stacktrace, which is the symptom that the hook on gitosis failed to process the new key.
我意识到当我为新用户推送密钥时,我得到了这个堆栈跟踪,这是 gitosis 上的钩子无法处理新密钥的症状。
remote: Traceback (most recent call last):
remote: File "/usr/local/bin/gitosis-run-hook", line 9, in <module>
remote: load_entry_point('gitosis==0.2', 'console_scripts', 'gitosis-run-hook')()
remote: File "/usr/local/lib/python2.7/dist-packages/gitosis-0.2-py2.7.egg/gitosis/app.py", line 24, in run
remote: return app.main()
remote: File "/usr/local/lib/python2.7/dist-packages/gitosis-0.2-py2.7.egg/gitosis/app.py", line 38, in main
remote: self.handle_args(parser, cfg, options, args)
remote: File "/usr/local/lib/python2.7/dist-packages/gitosis-0.2-py2.7.egg/gitosis/run_hook.py", line 81, in handle_args
remote: post_update(cfg, git_dir)
remote: File "/usr/local/lib/python2.7/dist-packages/gitosis-0.2-py2.7.egg/gitosis/run_hook.py", line 45, in post_update
remote: config=cfg,
remote: File "/usr/local/lib/python2.7/dist-packages/gitosis-0.2-py2.7.egg/gitosis/gitdaemon.py", line 95, in set_export_ok
remote: for (dirpath, repo, name) in walk_repos(config):
remote: File "/usr/local/lib/python2.7/dist-packages/gitosis-0.2-py2.7.egg/gitosis/gitdaemon.py", line 72, in walk_repos
remote: assert ext == '.git'
remote: AssertionError
The error was showing only ONCE, so I naively dismissed it as a momentary failure.
错误只显示ONCE,所以我天真地认为它是暂时的失败。
In practice, Gitosis was working only for my key, but it wasn't working for any of the users which I was trying to support. In the ~/.ssh/authorized_keys
I could not find the public key of the user which I thought I had just added. This is why my friend kept being asked for password every time he attempted cloning.
实际上,Gitosis 仅适用于我的密钥,但不适用于我试图支持的任何用户。在~/.ssh/authorized_keys
我找不到我以为刚刚添加的用户的公钥。这就是为什么我的朋友每次尝试克隆时都会被要求输入密码的原因。
I added debugging to the Gitosis configuration, by adding these two lines to gitosis.conf
我将调试添加到 Gitosis 配置中,将这两行添加到 gitosis.conf
[gitosis]
loglevel=DEBUG
I had to keep adding and removing users to the gitosis.conf file so that the hook would be triggered again. My debug log revealed
我不得不不断地在 gitosis.conf 文件中添加和删除用户,以便再次触发钩子。我的调试日志显示
remote: DEBUG:gitosis.gitdaemon:Deny 'syncShare'
remote: DEBUG:gitosis.gitdaemon:Walking 'legacy.d', seeing ['buildtools', 'QA_Dashboard']
remote: DEBUG:gitosis.gitdaemon:Walking 'legacy.d/buildtools', seeing ['.git', 'conf', 'scripts']
remote: Traceback (most recent call last):
etc ...
A-ha! As the hook performed the "walk" through the repository it had found a .git
directory under legacy.d/buildtools
and that is exactly where the assert ext == '.git'
occurred.
啊哈!当钩子在存储库中执行“遍历”时,它找到了一个.git
目录legacy.d/buildtools
,这正是assert ext == '.git'
发生的地方。
I had used the server to store a simple clone from some other repository. Notice, a plain clone, not a mirror or a bare repository. Like every clone it contained .git directory.
我曾使用服务器从其他存储库中存储一个简单的克隆。请注意,这是一个普通的克隆,而不是镜像或裸存储库。像每个克隆一样,它包含 .git 目录。
The hook in Gitosis doesn't know what to do with a .git directory. It thinks that it's a repository in an empty name and aborts. Once I wiped out that clone everything resumed working nicely.
Gitosis 中的钩子不知道如何处理 .git 目录。它认为它是一个空名称的存储库并中止。一旦我消灭了那个克隆,一切都恢复了正常工作。
回答by kadir malak
Editing authorized_keys should not be necessary normally.
通常不需要编辑authorized_keys。
I once had an authorization problem, the gitosis server kept asking me password even if I'd placed my public key before. I realized that gitosis gave me a warning "WARNING:gitosis.ssh:Unsafe SSH username in keyfile: '[email protected]'" when I've tried to commit and push my changes to gitosis.
我曾经遇到过授权问题,即使我之前已经放置了我的公钥,gitosis 服务器也会不断询问我密码。我意识到当我尝试提交并将更改推送到 gitosis 时,gitosis 给了我一个警告“警告:gitosis.ssh:密钥文件中的不安全 SSH 用户名:'[email protected]'”。
Changing the user@host part in the keyfile and keyfile name solved my problem. somehow gitosis did not like previous one.
更改密钥文件和密钥文件名中的 user@host 部分解决了我的问题。不知何故,gitosis 不喜欢前一个。
回答by StanV
Same problem, and in my case was that I had wrong authorized_keys in .ssh/. I must have messed it up at some point ...
同样的问题,就我而言,我在 .ssh/ 中有错误的 authorized_keys。我一定是在某个时候把它搞砸了......
回答by quickshiftin
Having moved to a new Ubuntu machine and run into this question myself, I saw a couple answers on here that got me moving in the right direction, namely using an absolute path to the .gitfiles for each repository.
搬到一台新的 Ubuntu 机器并自己遇到这个问题后,我在这里看到了几个答案,让我朝着正确的方向前进,即为每个存储库使用.git文件的绝对路径。
Experimenting a bit I noticed paths relative to the git user's home directory also worked, which shortened something like:
尝试了一下,我注意到相对于 git 用户主目录的路径也有效,它缩短了类似的内容:
git@host:/var/git/repositories/project.git
down to
向下
git@host:repositories/project.git
Playing a bit more I tried moving the project files from repositories right into git's home directory; now only the project is required:
多玩一点,我尝试将项目文件从存储库直接移动到 git 的主目录;现在只需要项目:
git@host:project.git
It's a bit hacky, but I doubt will cause any harm. Would be good to know what changed, as I was hosting gitosis on another Ubuntu (older) and was able to have the projects inside the repositories directory with the last notation from above.
这有点hacky,但我怀疑会造成任何伤害。知道发生了什么变化会很高兴,因为我在另一个 Ubuntu(旧版)上托管 gitosis 并且能够使用上面的最后一个符号将项目放在存储库目录中。
回答by altschuler
I finally got it working like this
我终于让它像这样工作了
git clone ssh://git@host:1337/home/git/repositories/gitosis-admin.git
where 1337 the port ssh is using.
其中 1337 端口 ssh 正在使用。