Connecting to gitosis server through an SSH tunnel

China☆狼群 提交于 2019-12-03 03:36:30

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.

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

On my Mac, I SSH tunnel localhost:22222 through the firewall to gitosis-server:22.

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

On my Mac, I created ~/.ssh/config that looks like this...

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

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

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:

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

(I use autossh instead of ssh to reconnect if I am disconnected, i.e. to keep connection up). Check that appropriate identities are added to SSH authentication agent:

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

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:

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

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 user@firewall.domain.com", 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)

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

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

This is an ssh issue and not (yet) a git issue.

ssh -v is your friend as it will give you debug information about what authentication methods and keys ssh 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 your id_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.

sshd -d -p 2022

If your 'normal' sshd service runs with extra parameters make sure to supply these to the debug version as well.

You say you can ssh to localhost:2222 successfully. To check that you have set up ~/.ssh/config correctly, can you ssh to just gitosis-server?

ssh gitosis-server

I had a similiar problem and I solved it with:

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

Maybe your keys were cached there?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!