I start up Ubuntu Linux, open a terminal, edit some code, and happily execute
git push origin master
However, after some period of time (sometime开发者_运维百科s 30 mins, sometimes a few hours), the exact same command will hang (no output at all).
When I try
ssh -v git@github.com
I get the following response:
OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010
debug1: Reading configuration data /home/avitus/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: auto-mux: Trying existing master
And then it hangs again. It seems as though I can no longer use SSH to git once I've SSH'ed to another server. Any ideas how to fix this? It is killing me having to reboot each time.
Update:
The problem goes away when I remove the following two lines (intended to facilitate connection sharing) from ~/.ssh/config
ControlMaster auto
ControlPath /tmp/ssh_mux_%h_%p_%r
Just turning my guess from a comment into an answer...
The last line in the output of ssh -v
:
debug1: auto-mux: Trying existing master
... tells you that SSH has been configured to look for an existing SSH connection to reuse. I suspect that this existing connection eventually gets stuck in some way, which would explain the behaviour you're seeing.
This connection sharing facility is described in the ControlMaster
section of the ssh_config(5)
man page. Essentially the "master" SSH session creates a socket in /tmp
which later sessions can connect to instead of having to go through the potentially length authentication step again. You have this option set to auto
, which means that this socket will be created and used automatically.
I struggled with this for a while before stumbling onto a help page buried under GitHub support:
https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port
Turns out my workplace had just the right magic combination of firewall/port protection to "almost" allow regular Git SSH access to GitHub, i.e. it worked "occasionally" but not reliably. ;-b
With this incantation in my $HOME/.ssh/config file, to use SSH Over HTTPS, I was suddenly able to access my GitHub repo from the command line via my SSH Key in GitHub:
Host github.com
User git
Hostname ssh.github.com
Port 443
PreferredAuthentications publickey
IdentityFile /home/XXX/.ssh/github_id_rsa
TCPKeepAlive yes # not sure if truly needed
IdentitiesOnly yes # not sure if truly needed
Enjoy! Jeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeem :)
精彩评论