通过SSH隧道连接到gitosis服务器

通过SSH隧道连接到gitosis服务器,git,ssh,firewall,gitosis,tunnel,Git,Ssh,Firewall,Gitosis,Tunnel,我的macbook上有一个SSH隧道设置,就像这样 $ ssh -o ServerAliveInterval=3 -N -L 22222:gitosis-server:22 user@firewall.domain.com $ssh-o ServerAliveInterval=3-N-L 2222:gitosis服务器:22user@firewall.domain.com 因此,我可以通过ssh连接到localhost:22222,并最终连接到防火墙后面的gitosis服务器上。 我创建了一个

我的macbook上有一个SSH隧道设置,就像这样

$ ssh -o ServerAliveInterval=3 -N -L 22222:gitosis-server:22 user@firewall.domain.com $ssh-o ServerAliveInterval=3-N-L 2222:gitosis服务器:22user@firewall.domain.com 因此,我可以通过ssh连接到localhost:22222,并最终连接到防火墙后面的gitosis服务器上。

我创建了一个本地id_rsa.pub文件,将其复制到gitosis服务器(运行Centos5),并使用

# sudo -H -u gitosis gitosis-init It 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 22222
#sudo-H-u发炎
这是成功的,因为我可以在/var/lib/gitosis/.ssh/authorized_keys中看到公钥。


回到macbook上,我设置了一个~/.ssh/config文件,其中包含以下内容

$ git clone gitosis@gitosis-server:gitosis-admin.git 主机gitosis服务器 主机名本地主机 HostKeyAlias gitosis-server.domain.com 22222端口 所以…我认为这个命令应该有效

Initialized empty Git repository in /Users/USER/Development/gitrepo/gitosis-admin/.git/ gitosis@localhost's password: $git克隆gitosis@gitosis-服务器:gitosis-admin.git 然而,当它要求密码时,它并没有……当公钥应该工作时

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: 已在/Users/USER/Development/gitrepo/gitosis admin/.Git中初始化空Git存储库/ gitosis@localhost的密码: 关于让git通过防火墙连接到gitosis服务器有什么想法吗

谢谢,
马特


编辑-从SSH尝试添加调试

我执行了这个命令,“ssh-vvv”gitosis@gitosis-服务器'。我得到一些调试回来,它似乎不喜欢我的身份

ssh gitosis-server
debug2:key:/Users/USER/.ssh/id_rsa.gitosis(0x1019b0) debug1:可以继续的身份验证:公钥、带麦克风的gssapi、密码 debug3:重新开始,传递了不同的列表公钥、带麦克风的gssapi、密码 debug3:首选公钥、键盘交互、密码 debug3:authmethod\u查找公钥 debug3:剩余首选项:键盘交互、密码 debug3:authmethod_是已启用的公钥 debug1:下一个身份验证方法:公钥 debug1:提供公钥:/Users/USER/.ssh/id\u rsa.gitosis debug3:发送\u pubkey\u测试 debug2:我们发送了一个公钥包,等待回复 debug1:可以继续的身份验证:公钥、带麦克风的gssapi、密码 debug2:我们没有发送数据包,请禁用方法 debug3:authmethod\u查找密码 debug3:剩余首选项:,密码 debug3:authmethod_是启用密码的 debug1:下一个身份验证方法:密码 gitosis@localhost的密码:
编辑2

好吧…肯定是一把坏钥匙。我再次仔细检查了所有密钥,当然发现gitosis服务器在authorized_keys文件中持有一个坏密钥

debug1:用户gitosis服务ssh连接方法的userauth请求无 调试1:尝试0失败0 debug1:PAM:正在初始化“gitosis” debug1:PAM:将PAM_RHOST设置为“firewall.domain.com” debug1:PAM:将PAM\u TTY设置为“ssh” debug1:用户gitosis服务ssh连接方法publickey的userauth请求 debug1:尝试1失败1 debug1:测试pkalg/pkblob是否可接受 debug1:暂时使用uid:102/103(e=0/0) debug1:正在尝试公钥文件/var/lib/gitosis/.ssh/authorized_keys debug1:还原\u uid:0/0 debug1:暂时使用uid:102/103(e=0/0) debug1:正在尝试公钥文件/var/lib/gitosis/.ssh/authorized_keys2 debug1:还原\u uid:0/0 来自FIRE.WALL.IP.ADDRESS端口52453 ssh2的gitosis公钥失败

我仔细查看了gitosis服务器上的authorized_keys文件……它是不正确的。我仔细检查了从工作站复制到/tmp中的公钥文件,该文件是正确的,但与授权密钥中的不同。我删除了服务器上的authorized_keys文件,并重新运行'sudo-H-u gitosis gitosis init 我通过编辑授权的_密钥并添加正确的密钥来手动更新它,然后我让它通过隧道在工作站上运行一两次。然后它像以前一样停止了工作。我回到gitosis服务器上的authorized_keys文件,果然……gitosis将其恢复为无法使用的旧密钥

为什么它要这样做…恢复到一个坏的公钥…即使在我尝试用上面的命令添加它之后…它没有改变它…然后手动改变它…这起作用了,但是git又恢复到坏的公钥

就像gitosis一直记着我放在那里的第一把钥匙…不让我把它改成正确的钥匙

令人沮丧的


Matt

您说您可以成功地通过ssh连接到
localhost:2222
。要检查您是否正确设置了
~/.ssh/config
,是否可以将ssh连接到gitosis服务器上

sshd -d -p 2022

这是一个
ssh
问题,而不是(目前)一个
git
问题

ssh-v
是您的朋友,因为它将为您提供有关
ssh
尝试使用的身份验证方法和密钥的调试信息

十有八九我发现这是关键文件权限的问题
ssh
喜欢您的
.ssh
目录和您的
id\u rsa
文件只能由“用户”写入,而我的umask默认允许组可写入文件
ssh-v
将告诉您您的情况是否如此

编辑

看起来sshd服务器不接受您的身份。我不知道您是否可以访问远程服务器,但在调试模式下运行
sshd
服务器可能会有所帮助

运行这样的操作允许在给定端口上建立一个连接(这样它就不会中断正常的
sshd
服务)并输出调试信息。这可能有助于调试服务器不喜欢您的身份的原因

$ autossh -M 20000 -f -N -L 2222:repo.or.cz:22 user@gateway.example.com
如果您的“正常”sshd服务使用额外参数运行,请确保也将这些参数提供给调试版本。

My setup for Simulate情形(正常工作) 我有类似的设置(由于某种原因,我使用的ISP波兰ISP Telekomunikacja S.A.(tpnet))阻止了空路由),它适用于我:

$ ssh-add -l
2048 d7:d3:69:f5:0f:f9:5e:aa:e0:0b:28:c2:03:42:09:66 /home/user/.ssh/id_dsa_gateway.example.com (DSA)
1024 11:a2:29:fe:37:12:a7:33:c4:23:b0:e1:82:92:e0:6a /home/user/.ssh/id_dsa_repo.or.cz (DSA)
Host repo.or.cz # NoHostAuthenticationForLocalhost yes HostName localhost Port 2222 $ ssh gitosis@gitosis-server Need SSH_ORIGINAL_COMMAND Connection to closed. $ ssh -v gitosis@gitosis-server [...] debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey debug1: Offering public key: /home/user/.ssh/id_dsa_gitosis-server debug1: Remote: Forced command: gitosis-server user [...] debug1: Authentication succeeded (publickey) yum remove gitosis rm -rf /var/lib/gitosis yum install gitosis sudo -H -u gitosis gitosis-init < /tmp/id_rsa.gitosis.pub #the correct key $ ssh -o ServerAliveInterval=3 -N -L 22222:gitosis-server:22 user@firewall.domain.com Host gitosis-server Hostname localhost IdentityFile ~/.ssh/id_rsa.gitosis HostKeyAlias gitosis-server.domain.com Port 22222
[srydberg@zeus ~]$ echo $SSH_AUTH_SOCK
/tmp/keyring-KXX3Aw/ssh
[srydberg@zeus tmp]$ sudo rm -rf keyring-KXX3Aw/