Scenario:
A. you are on a firewalled network, from where you can’t access github (remote port:9418 is not allowed)
or
B. you want to access a securized git server from home, but your IP is not on the git server’s whitelist.
and, of course, you have ssh access on a server that can do this.
A. Make a ssh tunnel to the git server
Me –> ServerWithSSHAccess –> GitServer
The comand to use is:
ssh ServerWithSSHAccess -L 2000:GitServer:22 -N ,
where 2000 is the local port you will connect to, and 22 is the remote port used to connect to the git server (if the connection uses git:// instead of default ssh port, change this to 9418). Then, instead of:
git clone GitServer/my_repo,
you must use:
git clone localhost:2000/my_repo
B. Automatically use tunnel to connect to git server
Furthermore, if the repository is already cloned on your computer, or you want to use the same addresses, you can config your ssh client to automatically pick the tunneled connection when connecting to the git server. In ~/.ssh/config, add:
Host GitServer
HostName 127.0.0.1
Port 2000
so now you can access your git repo as you were directly connected to it:
git clone GitServer/my_repo
git pull
git push
etc
Filed under: git, linux Tagged: | firewall, git, github, linux, ssh, ssh port forwarding, ssh tunelling
Awesome thanks. Was very useful today
I also needed to specify git+ssh: “git clone git+ssh://localhost:2000/my_repo“.
Just saying in case someone else ends up here