代码之家  ›  专栏  ›  技术社区  ›  Matt Mencel

通过ssh隧道连接到Gitosi服务器

  •  10
  • Matt Mencel  · 技术社区  · 17 年前

    我的MacBook上有一个ssh隧道设置,就像这样…

    $ ssh -o ServerAliveInterval=3 -N -L 22222:gitosis-server:22 user@firewall.domain.com

    所以我可以ssh到localhost:2222,并最终在防火墙后面的Gitosi服务器上完成。

    我创建了一个本地id_rsa.pub文件,将其复制到Gitosi服务器(运行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
    

    So...I'm thinking this command should work...

    $ git clone gitosis@gitosis-server:gitosis-admin.git

    It 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

    我仔细看了一下Gitosis服务器上的授权密钥文件……这是不正确的。我仔细检查了我从工作站复制到/tmp的公钥文件,它是正确的,但与授权的_密钥不同。我删除了服务器上的授权密钥文件,并重新运行“sudo-h-u gitosis gitosis init</tmp/id_rsa.gitosis.pub”。再次检查授权的_密钥文件…..但它仍然是错误的。

    我通过编辑授权的_键并添加正确的键手动更新了它,然后我让它从我的工作站通过通道工作了一两次。然后它像以前一样停止工作了。我回到Gitosi服务器上授权的_密钥文件中,果然……Gitosi已将其恢复为不起作用的旧密钥。

    为什么它会这样做……恢复到一个坏的公钥……即使在我尝试用上面的命令添加它之后……它未能更改它……然后手动更改它……这很有效,但是Git随后又恢复到坏的公钥。

    就像Gitosis一直记得我放在里面的第一把钥匙……不让我把它改成正确的钥匙。

    令人沮丧的。。。

    马特

    5 回复  |  直到 15 年前
        1
  •  3
  •   Matt Mencel    17 年前

    跟进:

    我不知道为什么Gitosis坚持重用一个坏的公钥。试图强迫它取正确的钥匙不起作用。

    所以今天我刚把Gitosi软件包卸下重新安装在我的Centos5盒子上。

    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
    

    在我的Mac上,我ssh将本地主机22222通过防火墙传输到gitosis服务器22。

    $ ssh -o ServerAliveInterval=3 -N -L 22222:gitosis-server:22 user@firewall.domain.com

    在我的Mac上,我创建了~/.ssh/config,看起来像这样…

    Host gitosis-server
    Hostname localhost
    IdentityFile ~/.ssh/id_rsa.gitosis
    HostKeyAlias gitosis-server.domain.com
      Port 22222

    然后…按照这个网站上的说明…

    http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way

    …之后的一切… “这里发生了一些很酷的魔法。在本地计算机上运行此项:“ …只是工作…除了记住将用户名“git”替换为“gitosis”。

    希望那些胡说八道的话能帮助别人。还感谢我在这里得到的建议……它帮助缩小了问题的范围。

    马特

        2
  •  2
  •   Jakub Narębski adamtaub    17 年前

    我对类似情况的设置(工作)

    我有类似的设置 repo.or.cz (由于某种原因,我使用的ISP、波兰ISP Telekomunikacja S.A.(TPnet))阻止了空路由,它对我有效:

    在尝试连接之前,我运行以下命令run来设置ssh tunel:

    $ autossh -M 20000 -f -N -L 2222:repo.or.cz:22 user@gateway.example.com
    

    (我用 autossh 而不是 ssh 如果断开连接,重新连接,即保持连接)。检查是否将适当的标识添加到ssh身份验证代理:

    $ 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)
    

    我用 keychain 只需在登录时为我的专用ssh密钥提供一次密码。

    我在我的 ~/.ssh/config :

    Host repo.or.cz
            # NoHostAuthenticationForLocalhost yes
            HostName localhost
            Port 2222
    

    这个设置对我来说毫无问题。


    调试您的情况

    关于调试你的情况?

    首先,我将检查是否可以使用“ssh user@firewall.domain.com”登录到网关,以检查是否可以设置ssh隧道。如果您使用的是Linux,那么您可以使用例如 netstat --tcp 检查是否建立了到网关的连接;在其他操作系统和环境中,您可以找到类似的实用程序。

    检查您是否能正确连接到Gitosis。 (如果我没记错的话 gitorious 使用gitosis管理通过ssh的访问,所以我在下面的示例中使用了gitorious的响应)

    $ ssh gitosis@gitosis-server
    Need SSH_ORIGINAL_COMMAND
                                 Connection to  closed.
    

    如果它没有做与上面类似的事情(repo.or.cz返回“致命:你认为我是什么?”贝壳?”,Github返回“嗨,用户!您已成功通过身份验证,但Github不提供shell访问。”),请使用“ssh-v gitosis@gitosis server”检查失败的位置:

    $ 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)
    
        3
  •  2
  •   CB Bailey    17 年前

    这是一个 ssh 问题而不是 git 问题。

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

    十分之九我发现这是一个关键文件的权限问题。 嘘 喜欢你 .ssh 目录和您的 id_rsa 文件只能由“用户”写入,默认情况下,我的umask允许组可写入文件。 SSH-V 会告诉你情况是否如此。

    编辑

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

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

    sshd -d -p 2022
    

    如果您的“普通”sshd服务使用额外的参数运行,请确保也将这些参数提供给调试版本。

        4
  •  1
  •   Greg Hewgill    17 年前

    你说你可以 localhost:2222 成功地。检查您是否已设置 ~/.ssh/config 对,你能不能用ssh gitosis-server ?

    ssh gitosis-server
    
        5
  •  0
  •   srydberg    15 年前

    我有一个相似的问题,我用以下方法解决了它:

    [srydberg@zeus ~]$ echo $SSH_AUTH_SOCK
    /tmp/keyring-KXX3Aw/ssh
    [srydberg@zeus tmp]$ sudo rm -rf keyring-KXX3Aw/
    

    也许你的钥匙被缓存在那里?