Really verbose way to test Git connection over SSH?

150,611

Solution 1

Environment variable

From Git version 2.3.0, you can use the environment variable GIT_SSH_COMMAND and pass the -v verbose argument like this:

GIT_SSH_COMMAND="ssh -v" git clone example

To be extra verbose, make it -vvv:

GIT_SSH_COMMAND="ssh -vvv" git clone example

Git config

From Git version 2.10.0, which will in Ubuntu 17.04's repos, you can save this configuration globally, or per repo as in this example:

git config core.sshCommand "ssh -vvv"
git pull

Solution 2

I had a similar problem. For debugging I added a line in my ssh_config. Here is how I've done it:

git remote -v

There you will find a line like this:

origin  [email protected]:me/test.git (fetch)
origin  [email protected]:me/test.git (push)

In this case the host is github.com. Now you can add a Host-Entry in you ssh config:

vim ~/.ssh/config

And add:

Host github.com
    LogLevel DEBUG3

On using git operations, you should get plenty of debug messages, now. To get lesser debug messages, try using DEBUG1

For GIT versions >= 2.3.0 see the answer from @Flimm for a smarter solution.

Solution 3

Reading through man git, there are some useful environmental variables you can set, GIT_TRACE_PACKET and GIT_TRACE. For example:

GIT_TRACE_PACKET=true git clone ssh://[...]

A bit late to the game, but hopefully this helps someone!

Solution 4

Per man ssh:

 -v      Verbose mode.  Causes ssh to print debugging messages about its progress.  This
         is helpful in debugging connection, authentication, and configuration problems.
         Multiple -v options increase the verbosity.  The maximum is 3.

So, try ssh -v. If that doesn't tell you what you need to know, you can add one or two vs for even more detailed debugging information. For Github in particular, try ssh -vvvT [email protected].

Usually, in my experience, an SSH session hanging during setup happens when the client can't complete the chosen authentication method. Check that your private key is in the right place with the right permissions and matches the public key you've given Github.

Solution 5

I don't see a way to tell git(1) the external command to use for ssh(1), but as a workaround, simply rename /path/to/ssh to /path/to/ssh.orig, create a shell script wrapper /path/to/ssh, and add in the -v flags:

$ sudo mv /usr/bin/ssh /usr/bin/ssh.orig
$ sudo vim /usr/bin/ssh
$ cat /usr/bin/ssh
#!/bin/sh

if [ -x /usr/bin/ssh.orig ]; then
    exec /usr/bin/ssh.orig -v -v -v "${@}"
fi

$ sudo chmod a+x /usr/bin/ssh

I get verbose output when executing git commands operating over an ssh transport. Once done debugging, delete the script and restore /path/to/ssh.orig to /path/to/ssh.

Share:
150,611

Related videos on Youtube

IQAndreas
Author by

IQAndreas

SOreadytohelp Developer with multiple languages under my belt; primarily ActionScript 3, but also includes PHP, Java, and JavaScript. Just to be clear, I hate JavaScript: it's weakly typed, and its inheritance system is a joke. PHP isn't big on my list either. Yet, since the web uses them, I'm forced to work in them. IQAndreas.com - Main Website blog.iqandreas.com - Programming Blog GitHub.com/IQAndreas - GitHub Account and Repositories @IQAndreas - Twitter

Updated on September 18, 2022

Comments

  • IQAndreas
    IQAndreas over 1 year

    When using GIT, I have problems with using GIT over SSH, and since it works just fine both from work, and at home with a different modem, it's obviously my home modem that is acting up. I have no problems connecting over HTTP.

    So, I'm assuming it is an SSH problem, but I'm no expert at using it directly. Is there any command I can run which sets up a "test" connection, and lets me know exactly when and where along the line the problem occurs?

    Pretty much all "larger" commands (such as fetch, clone, or push with much data) from git (even when run with -v) just "hang" in the middle of connecting remotely with no indication as to why they have stopped, so they are of no use.

    Is there any way I can get more details on what is happening in the SSH connection?

  • IQAndreas
    IQAndreas over 10 years
    Thanks for the answer, but I should probably have asked the question differently (since GitHub doesn't allow direct SSH connections like that). I edited the post and title, but is it better to discard this one and create a new question instead?
  • tgies
    tgies over 10 years
    @IQAndreas, GitHub does allow SSH connections like that in the sense that the authentication phase will be carried out and if the problem is indeed happening in the SSH step, you'll see it that way. If you're finding that you can't even get that far, something is going on that's preventing the connection from even being made.
  • IQAndreas
    IQAndreas over 10 years
    I'm being authenticated just fine, and sometimes push/pull on the repo with no problems. But often it just "hangs" in the middle of the command and won't continue (especially when I transfer large amounts of data such as a large clone or push). There are no error messages, it just sits there and doesn't continue.
  • muru
    muru over 9 years
    Instead of moving files in /usr/bin, consider putting the wrapper script in /usr/local/bin.
  • Coderer
    Coderer over 9 years
    At least on my strange Windows install, the environment variable GIT_SSH can be set to point to the binary you want Git to use.
  • Trendfischer
    Trendfischer about 9 years
    This is helpful, but you do not get any messages about connection problems with SSH. But if the SSH connection works, this is the way to debug further on.
  • Paulo Oliveira
    Paulo Oliveira over 8 years
    For me at least, If I do this: GIT_SSH_COMMAND="ssh -v" git clone example I can debug SSH version, it's printed after Cloning into message, but fail at git clone. After I remove GIT_SSH_COMMAND it works. In the end, served the purpose.
  • Joseph K. Strauss
    Joseph K. Strauss about 7 years
    For a one-time this will be better: git -c core.sshCommand="ssh -vvv" pull
  • Azodium
    Azodium almost 6 years
    git config --global core.sshCommand "ssh -vvv" git clone example
  • Scott Prive
    Scott Prive over 5 years
    As said, you definitely don't want to modify the original ssh file, but I would have reservations about the workaround in /usr/local/. It's not transparent, and it is easily stomped on. BETTER: put your workaround script into $HOME/bin and add that new bin dir in your user's $PATH variable, ahead of other PATH segments. And before doing that, I'd check if there isn't an ENV var solution that's even better (this answer is old).
  • khaverim
    khaverim over 4 years
    what about older versions e.g. 1.8?
  • RajaRaviVarma
    RajaRaviVarma about 4 years
    I will happy that there is a solution for everything in opensource ecosystem. Thanks