通过 SSH 隧道连接到 gitosis 服务器
我的 macbook 上有一个 SSH 隧道设置,就像这样...
$ ssh -o ServerAliveInterval=3 -N -L 22222:gitosis-server:22 [email protected]
所以我可以 ssh 到 localhost:22222 并最终到达防火墙后面的 gitosis 服务器。
我创建了一个本地 id_rsa.pub 文件,将其复制到 gitosis 服务器(运行 Centos5),然后使用...将其导入到 gitosis 中,
# sudo -H -u gitosis gitosis-init因为我可以在 /var 中看到公钥,所以成功了/lib/gitosis/.ssh/authorized_keys。
回到我的 macbook 上,我使用以下内容设置了一个 ~/.ssh/config 文件...Host gitosis-server Hostname localhost HostKeyAlias gitosis-server.domain.com Port 22222所以...我认为这个命令应该可以工作...
$ git clone gitosis@gitosis-server:gitosis-admin.git但是它不会,因为它要求输入密码... .当公钥应该起作用时。
Initialized empty Git repository in /Users/USER/Development/gitrepo/gitosis-admin/.git/ gitosis@localhost's password:关于让 git 工作到防火墙后面的 gitosis 服务器有什么想法吗?
谢谢,
Matt
编辑 - 从 SSH 尝试添加调试
我执行了此命令“ssh -vvv gitosis@gitosis-server”。 我进行了一些调试,它似乎不喜欢我的身份。
debug2: key: /Users/USER/.ssh/id_rsa.gitosis (0x1019b0) debug1: Authentications that can continue: publickey,gssapi-with-mic,password debug3: start over, passed a different list publickey,gssapi-with-mic,password debug3: preferred publickey,keyboard-interactive,password debug3: authmethod_lookup publickey debug3: remaining preferred: keyboard-interactive,password debug3: authmethod_is_enabled publickey debug1: Next authentication method: publickey debug1: Offering public key: /Users/USER/.ssh/id_rsa.gitosis debug3: send_pubkey_test debug2: we sent a publickey packet, wait for reply debug1: Authentications that can continue: publickey,gssapi-with-mic,password debug2: we did not send a packet, disable method debug3: authmethod_lookup password debug3: remaining preferred: ,password debug3: authmethod_is_enabled password debug1: Next authentication method: password gitosis@localhost's password:
编辑2
好吧...绝对是一把坏钥匙。 我再次仔细检查了所有密钥,当然发现 gitosis 服务器在authorized_keys 文件中持有错误的密钥。
debug1:用户 gitosis 服务的 userauth-请求 ssh-连接方法 无 debug1:尝试 0 次失败 0 debug1:PAM:初始化“gitosis” debug1:PAM:将 PAM_RHOST 设置为“firewall.domain.com” debug1:PAM:将 PAM_TTY 设置为“ssh” debug1:用户 gitosis 服务的 userauth-请求 ssh-连接方法 publickey debug1:尝试 1 失败 1 debug1:测试 pkalg/pkblob 是否可接受 调试1:暂时使用_uid:102/103(e = 0/0) debug1:尝试公钥文件 /var/lib/gitosis/.ssh/authorized_keys 调试1:恢复uid:0/0 调试1:暂时使用_uid:102/103(e = 0/0) debug1:尝试公钥文件 /var/lib/gitosis/.ssh/authorized_keys2 调试1:恢复uid:0/0 来自 FIRE.WALL.IP.ADDRESS 端口 52453 ssh2 的 gitosis 的公钥失败
我仔细查看了 gitosis 服务器上的authorized_keys 文件......发现它是不正确的。 我仔细检查了从工作站复制到 /tmp 的公钥文件,它是正确的,但与authorized_keys 中的内容不同。 我删除了服务器上的authorized_keys文件并重新运行'sudo -H -u gitosis gitosis-init < /tmp/id_rsa.gitosis.pub'。 再次检查authorized_keys文件……还是错误。
我通过编辑authorized_keys并添加正确的密钥来手动更新它,然后我让它通过隧道从我的工作站工作一两次尝试。 然后它就像以前一样停止工作了。 我回到 gitosis 服务器上的authorized_keys 文件,果然....gitosis 已将其恢复为不起作用的旧密钥。
为什么要这样做......恢复到一个错误的公钥......即使在我尝试使用上述命令添加它之后......也无法更改它......然后手动更改它......这有效,但 git 然后又恢复到坏的状态。
就像 gitosis 一直记住我放在那里的第一个密钥......并且不会让我将其更改为正确的密钥。
令人沮丧...
马特
I've got an SSH tunnel setup on my macbook, like this...
$ ssh -o ServerAliveInterval=3 -N -L 22222:gitosis-server:22 [email protected]
So I can ssh to localhost:22222 and will end up on the gitosis-server behind the firewall.
I've created a local id_rsa.pub file, copied it into the gitosis server(running Centos5), and imported it into gitosis using...
# sudo -H -u gitosis gitosis-initIt was successful as I can see the public key in /var/lib/gitosis/.ssh/authorized_keys.
Back on my macbook I setup a ~/.ssh/config file with the following...Host gitosis-server Hostname localhost HostKeyAlias gitosis-server.domain.com Port 22222So...I'm thinking this command should work...
$ git clone gitosis@gitosis-server:gitosis-admin.gitIt does not however as it comes up asking for a password....when the public keys should be working.
Initialized empty Git repository in /Users/USER/Development/gitrepo/gitosis-admin/.git/ gitosis@localhost's password:Any ideas on getting git working through to a gitosis server behind a firewall?
Thanks,
Matt
EDIT - Adding Debug From SSH Attempt
I did this command, 'ssh -vvv gitosis@gitosis-server'. I get some debugging back and it doesn't seem to like my Identity.
debug2: key: /Users/USER/.ssh/id_rsa.gitosis (0x1019b0) debug1: Authentications that can continue: publickey,gssapi-with-mic,password debug3: start over, passed a different list publickey,gssapi-with-mic,password debug3: preferred publickey,keyboard-interactive,password debug3: authmethod_lookup publickey debug3: remaining preferred: keyboard-interactive,password debug3: authmethod_is_enabled publickey debug1: Next authentication method: publickey debug1: Offering public key: /Users/USER/.ssh/id_rsa.gitosis debug3: send_pubkey_test debug2: we sent a publickey packet, wait for reply debug1: Authentications that can continue: publickey,gssapi-with-mic,password debug2: we did not send a packet, disable method debug3: authmethod_lookup password debug3: remaining preferred: ,password debug3: authmethod_is_enabled password debug1: Next authentication method: password gitosis@localhost's password:
EDIT 2
OK...Definately a bad key. I double checked all my keys again and of course found the gitosis-server was holding a bad key in the authorized_keys file.
debug1: userauth-request for user gitosis service ssh-connection method none
debug1: attempt 0 failures 0
debug1: PAM: initializing for "gitosis"
debug1: PAM: setting PAM_RHOST to "firewall.domain.com"
debug1: PAM: setting PAM_TTY to "ssh"
debug1: userauth-request for user gitosis service ssh-connection method publickey
debug1: attempt 1 failures 1
debug1: test whether pkalg/pkblob are acceptable
debug1: temporarily_use_uid: 102/103 (e=0/0)
debug1: trying public key file /var/lib/gitosis/.ssh/authorized_keys
debug1: restore_uid: 0/0
debug1: temporarily_use_uid: 102/103 (e=0/0)
debug1: trying public key file /var/lib/gitosis/.ssh/authorized_keys2
debug1: restore_uid: 0/0
Failed publickey for gitosis from FIRE.WALL.IP.ADDRESS port 52453 ssh2
I took a closer look at the authorized_keys file on the gitosis server....and it was incorrect. I double checked the public key file I had copied into /tmp from my workstation and it was the correct one, but different from what was in authorized_keys. I deleted the authorized_keys file on the server and reran the 'sudo -H -u gitosis gitosis-init < /tmp/id_rsa.gitosis.pub'. Checked the authorized_keys file again.....and it was still wrong.
I updated it manually by editing authorized_keys and adding the correct key, and then I got it to work from my workstation through the tunnel for one or two tries. Then it stopped working as before. I went back in to the authorized_keys file on the gitosis server, and sure enough....gitosis had reverted it back to the old key that does not work.
Why is it doing this....reverting back to a bad public key....even after I tried adding it with the above command...which failed to change it....then changed it manually....which worked but git then reverted back to the bad one again.
It's like gitosis keeps remembering the first key I put in there....and won't let me change it to the corrected key.
Frustrating...
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
后续:
我不确定为什么 gitosis 坚持重用一个坏的公钥。 试图强制它获取正确的密钥没有成功。
所以今天我刚刚在我的 CentOS5 机器上删除并重新安装了 gitosis 软件包。
在我的 Mac 上,我通过防火墙 SSH 隧道 localhost:22222 到达 gitosis-server:22。
在我的 Mac 上,我创建了 ~/.ssh/config ,如下所示...
然后...按照本网站上的说明...
http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way
...之后的一切... “这里发生了一些很酷的魔法。在本地计算机上运行它:”...正常工作...除了记住将用户名“git”替换为“gitosis”。
希望所有这些废话对某人有所帮助。 也感谢我在这里得到的建议......它有助于缩小问题范围。
马特
Followup:
I'm not sure why gitosis insisted on reusing a bad public key. Trying to force it to take the correct key did not work.
So today I just removed and reinstalled the gitosis package on my CentOS5 box.
On my Mac, I SSH tunnel localhost:22222 through the firewall to gitosis-server:22.
On my Mac, I created ~/.ssh/config that looks like this...
Then...following the instructions on this site...
http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way
...everything after... "Here some cool magic happens. Run this on your local machine:"... just works... except remember to replace the username "git" with "gitosis".
Hope all that nonsense helps somebody. Thanks also for the suggestions I got here....it helped narrow down the problem.
Matt
我针对类似情况的设置(工作)
我对 repo.or.cz 有类似的设置(这是出于某种原因空路由被我使用的 ISP(波兰 ISP Telekomunikacja SA (tpnet))阻止,它对我有用:
我在尝试连接之前运行以下命令来设置 SSH 通道:(
我使用
autossh
而不是ssh
在断开连接时重新连接,即保持连接)。 检查是否将适当的身份添加到 SSH 身份验证代理中:我使用 keychain 来提供我的 SSH 私钥的密码仅在登录时输入一次。
我在我的
~/.ssh/config
中进行了以下设置:此设置对我来说没有问题。
调试您的情况
至于调试您的情况?
首先,我会检查是否可以使用“ssh [email protected]<登录网关/a>”,检查是否可以建立 SSH 隧道。 如果您使用的是 Linux,您可以使用例如
netstat --tcp
来检查是否已建立到网关的连接; 在其他操作系统和环境中,您可以找到类似的实用程序。检查是否可以正确连接到gitosis。 (如果我没记错的话 gitorious 正在使用 gitosis 来管理通过 SSH 的访问,所以我在示例中使用了 gitorious 的响应 ,
如果它没有执行与上面类似的操作(repo.or.cz 返回“fatal: What do you think I am? A shell?”,GitHub 返回“Hi user!您已成功通过身份验证 但 GitHub 不提供 shell 访问。”),使用“ssh -v gitosis@gitosis-server”检查失败的位置:
My setup for similar situation (working)
I have similar setup for repo.or.cz (which is for some reason null-route blocked by ISP I use, Polish ISP Telekomunikacja S.A. (tpnet)), and it works for me:
I run the following command run to set up SSH tunel before attempting to connect:
(I use
autossh
instead ofssh
to reconnect if I am disconnected, i.e. to keep connection up). Check that appropriate identities are added to SSH authentication agent:I use keychain to have to provide passwords for my private SSH keys only once, at login.
I have the following set up in my
~/.ssh/config
:This setup works for me without problems.
Debugging your situation
As for debugging your situation?
First, I would check if I can log in to gateway using "ssh [email protected]", to check if SSH tunnel can be set up. If you are on Linux you can use for example
netstat --tcp
to check if there is connection established to gateway; on other operating systems and environments you can find similar utilities.Check if you can connect correctly to gitosis. (If I remember correctly gitorious is using gitosis for managing access via SSH, so I used response from gitorious in example below)
If it doesn't do something similar to above (repo.or.cz returns "fatal: What do you think I am? A shell?", GitHub returns "Hi user! You've successfully authenticated, but GitHub does not provide shell access."), check where it fails with "ssh -v gitosis@gitosis-server":
这是一个
ssh
问题,而不是一个git
问题。ssh -v
是您的朋友,因为它会为您提供有关ssh
尝试使用哪些身份验证方法和密钥的调试信息。我十有八九发现这是关键文件权限的问题。
ssh
喜欢您的.ssh
目录和id_rsa
文件只能由“用户”写入,而我的 umask 默认情况下允许组可写文件。ssh -v
会告诉您您的情况是否属于这种情况。编辑
sshd 服务器看起来确实不接受您的身份。 我不知道您是否有权访问远程服务器,但在调试模式下运行 sshd 服务器可能会有所帮助。
运行类似的命令允许给定端口上的一个连接(这样就不会中断正常的 sshd 服务)并输出调试信息。 这可能有助于调试服务器不喜欢您的身份的原因。
如果您的“正常”sshd 服务使用额外参数运行,请确保也将这些参数提供给调试版本。
This is an
ssh
issue and not (yet) agit
issue.ssh -v
is your friend as it will give you debug information about what authentication methods and keysssh
is attempting to use.Nine times out of ten I find that this is an issue with permissions on key files.
ssh
likes your.ssh
directory and yourid_rsa
file to be only writeable by 'user' and my umask allows group writeable files by default.ssh -v
will tell you if this is the case in your situation.Edit
It does look like the sshd server doesn't accept your identity. I don't know if you have access to the remote server, but running an
sshd
server in debug mode might help.Running something like this allows one connection on the given port (so that it doesn't interrupt the normal
sshd
service) and outputs debug information. This may help debug why the server doesn't like your identity.If your 'normal' sshd service runs with extra parameters make sure to supply these to the debug version as well.
您说您可以成功 ssh 到 localhost:2222 。 要检查您是否已正确设置
~/.ssh/config
,您可以 ssh 到gitosis-server
吗?You say you can ssh to
localhost:2222
successfully. To check that you have set up~/.ssh/config
correctly, can you ssh to justgitosis-server
?我遇到了类似的问题,我解决了它:
也许你的密钥缓存在那里?
I had a similiar problem and I solved it with:
Maybe your keys were cached there?