Sunday, November 16, 2008

Why I love GIT and GITHUB..:)

.......is I can push my changes to public repo, sitting behind one of those corporate network, which allows only http/https through them...

On GITHUB we can host our repos and access from anywhere..( from behind corporate firewalls, proxy...)

There are many links out there over internet, which helps us how to do that...but the basic thing what I was doing wrong was trying to push on ssh's default port 22 and to server github.com, rather than ssh.github.com.

Finally reading this end, I was successful in git-push!. Here is how we can do that....

Variables to be set before proceeding.

++ For those who are lucky ( got root / sudo access ) ++

1. Install corkscrew...( apt-get upgrade corkscrew)
2. edit ~/.ssh/config

Host 65.74.177.142
ProxyCommand corkscrew 8080 %h %p ~/.ssh/proxyauth
Port 443
ServerAliveInterval 10
IdentityFile /home/dilipm/.ssh/github

Where,
- 65.74.177.142 is the IP of ssh.github.com. found from nslookup
- File ~/.ssh/proxyauth contains your username and passwd of proxy server. in format username:passwd

- 443, this is where I was doing wrong! I was trying port 22.
- /home/dilipm/.ssh/github, path of my private key

3. set env variable GIT_PROXY_COMMAND=/home/dilipm/.ssh/proxy_cmd_for_github.
where cat /home/dilipm/.ssh/proxy_cmd_for_github is,
corkscrew 8080 65.74.177.142 443 ~/.ssh/proxyauth


That's it...now just do ssh -v git@ 65.74.177.142
At the first attempt the server's (ssh.github.com) fingerprint will be added to local know_hosts file.

++ For those who are unlucky ( don't have root access ) ++

1. download the perl script of Mark suter..
ssh-https-tunnel

2. change the proxy details as required...

3. change the ProxyCommand in ~/.ssh/config as below,
ProxyCommand ~/ssh-https-tunnel.pl %h %p

that's it....try doing ssh -v git@65.74.177.142

6 comments:

Anonymous said...

Hi! Thanks for the tutorial. I would suggest putting association between 65.74.177.142 and ssh.github.com inside the /etc/hosts to keep the it in one, standard place.

Also what about the project origin? Did you have to change it to git@ssh.github.com <...> instead of standard git@github.com <...>? I had to and since then it works fine for me.

Thanks!
Jakub Pawlowicz

Unknown said...

I've tried but fails :

[~]# ssh -v g...@ssh.github.com
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
debug1: Reading configuration data /home/user/.ssh/config
debug1: Applying options for ssh.github.com
debug1: Executing proxy command: exec ~/ssh-https-tunnel.pl
ssh.github.com 443
debug1: identity file /home/user/.ssh/identity type -1
debug1: identity file /home/user/.ssh/id_rsa type 1
debug1: identity file /home/user/.ssh/id_dsa type -1
/home/user/ssh-https-tunnel.pl: CONNECT failed: SSH-2.0-
OpenSSH_4.7
ssh_exchange_identification: Connection closed by remote host

[~]# cat ~/.ssh/config
host ssh.github.com
ProxyCommand ~/ssh-https-tunnel.pl %h %p
Port 443
ServerAliveInterval 10

Any suggestion will be greatly appreciated
Luca

RayRacine said...

Seems more then is truly necessary.

1) Create a github alias in your .ssh/config to use ssh on port 443
cat .ssh/config
Host github
User git
Port 443
Hostname ssh.github.com

2) Modify your .git/config file to use said alias
cat /myproject/.git/config
...
[remote "origin"]
url = git@github:MyProj/cdap2.git
...

Tim Cuthbertson said...

thanks grey lens man. Much simpler.

I still needed the ProxyCommand line for mine, and I used "Host: github.com" because that way I don't have to use anything unusual in my git remote.

To the original author: Why are you using a hard-coded IP?

Venkatesh said...

thanks grey lens man, your idea worked for me on Windows 7, i am now able to connect to github.com thru 443.

dilipm79 said...

ah! never got time to catch up. I wish to work full time on GIT. I'm available for hire :)