3

While my Linux machines can access the hosted repositories on the NAS using its hostname, my Windows machine fails to access it from command line / Visual Studio Code. During my debugging attempts I found a way so that at least TortoiseGit can access the repositories: I had to add an env var GIT_SSH_COMMAND=ssh -vvv (besides the already existing GIT_SSH=C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe).

When I issue a git pull via cmd for a repository accessed in Git config via url = ssh://gituser@my-devices-hostname/volume1/git/reponame.git I get the following output:

OpenSSH_8.1p1, OpenSSL 1.1.1d 10 Sep 2019 debug1: Reading configuration data /etc/ssh/ssh_config debug2: resolving "my-devices-hostname" port 22 debug2: ssh_connect_direct debug1: Connecting to my-devices-hostname [192.168.0.50] port 22. getaddrinfo: atch: Name or service not known ssh: connect to host my-devices-hostname port 22: failure fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 

When I replace the hostname by a static IP I get the same error:

OpenSSH_8.1p1, OpenSSL 1.1.1d 10 Sep 2019 debug1: Reading configuration data /etc/ssh/ssh_config debug2: resolve_canonicalize: hostname 192.168.0.50 is address debug2: ssh_connect_direct debug1: Connecting to 192.168.0.50 [192.168.0.50] port 22. getaddrinfo: atch: Name or service not known ssh: connect to host 192.168.0.50 port 22: failure fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 

When doing the same with TortoiseGit, everything works fine, I get:

OpenSSH_8.1p1, OpenSSL 1.1.1d 10 Sep 2019 debug1: Reading configuration data /etc/ssh/ssh_config debug2: resolving "my-devices-hostname" port 22 debug2: ssh_connect_direct debug1: Connecting to my-devices-hostname [192.168.0.50] port 22. debug1: Connection established. ... 

I've recently set up a new DSL router (Fritz!Box 7590), maybe this is somehow related. Since I guessed that the problem could be related to IPv6, I've disabled IPv6 on the Synology NAS, but no change.

Update: fedrik asked me to perform a manual ssh. Here are the results:

ssh gituser@my-devices-hostname fatal: Interactive git shell is not enabled. hint: ~/git-shell-commands should exist and have read and execute access. Connection to my-devices-hostname closed. 

and surprisingly:

ssh [email protected] ssh: connect to host 196.168.0.50 port 22: Connection timed out 

I updated my Git- and Tortoise installation, now I get

ssh [email protected] fatal: Interactive git shell is not enabled. hint: ~/git-shell-commands should exist and have read and execute access. Connection to 192.168.0.50 closed. 

The hostname based ssh remained the same.

Inspired by the answer from VonC, I checked if there are multiple instances of ssh installed on my system. I found the following:

C:\Windows\System32\OpenSSH\ssh.exe C:\Program Files\Git\usr\bin\ssh.exe 

So I checked (after updating Tortoise and Git for Windows), which one is used. First, I left GIT_SSH_COMMAND=ssh -vvv:

git pull OpenSSH_8.4p1, OpenSSL 1.1.1h 22 Sep 2020 debug1: Reading configuration data /etc/ssh/ssh_config debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Users/user/.ssh/known_hosts' debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Users/user/.ssh/known_hosts2' debug2: resolving "my-devices-hostname" port 22 debug2: ssh_connect_direct debug1: Connecting to my-devices-hostname [192.168.0.50] port 22. getaddrinfo: atch: Name or service not known ssh: connect to host my-devices-hostname port 22: failure fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. "C:\Program Files\Git\usr\bin\ssh.exe" -vvv [email protected] OpenSSH_8.4p1, OpenSSL 1.1.1h 22 Sep 2020 debug1: Reading configuration data /etc/ssh/ssh_config debug2: resolve_canonicalize: hostname 192.168.0.50 is address debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Users/bjoer/.ssh/known_hosts' debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Users/bjoer/.ssh/known_hosts2' debug2: ssh_connect_direct debug1: Connecting to 192.168.0.50 [192.168.0.50] port 22. debug1: Connection established. 

After I changed the env var: GIT_SSH_COMMAND=C:/Windows/System32/OpenSSH/ssh.exe -vvv I got this:

git pull OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5 debug3: Failed to open file:C:/Users/user/.ssh/config error:2 debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2 debug2: resolving "my-devices-hostname" port 22 debug2: ssh_connect_direct: needpriv 0 debug1: Connecting to my-devices-hostname [192.168.0.50] port 22. getaddrinfo: atch: Der angegebene Host ist unbekannt. ssh: connect to host my-devices-hostname port 22: failure fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. C:\Windows\System32\OpenSSH\ssh.exe -vvv [email protected] OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5 debug3: Failed to open file:C:/Users/user/.ssh/config error:2 debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2 debug2: resolve_canonicalize: hostname 192.168.0.50 is address debug2: ssh_connect_direct: needpriv 0 debug1: Connecting to 192.168.0.50 [192.168.0.50] port 22. debug1: Connection established. 

When I unset GIT_SSH and GIT_SSH_COMMAND env vars, I get this:

git pull getaddrinfo: atch: Name or service not known ssh: connect to host my-devices-hostname port 22: failure fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 

So, I can connect via SSH to the Git server, but when issues from the Git executable itself, it fails. When I launch up a WSL on the same machine, I can perform a git pull without problems.

Any suggestions on how to tackle this issue?

2
  • This is some form of networking issue. Can also be caused by an old git version coupled with newer versions of supporting libraries - or the other way around. Since you're using Tortoise that can also be part of the cause. Can you do a plain ssh to the host? Commented Dec 27, 2020 at 12:18
  • Thanks for the tips, fredrik! I've incorporated my previous answer in the question for better readability. Commented Dec 28, 2020 at 11:04

3 Answers 3

7

I was getting this error as a result of setting git config --global ssh.variant plink. By setting git config --global ssh.variant ssh, this error went way. The problem seems to be that git was passing a -batch option, which plink was interpreting as a -b option (hence the strange error involving "atch".

Sign up to request clarification or add additional context in comments.

Comments

1

Although this issue appeared somewhat after I installed a new router, the root cause was a defective setup of the Git server on my Synology NAS. After setting up the Git server from scratch following these steps, everything worked fine again:

Setup user and folder

  • Install WebDAV package via Diskstation Package Manager
  • Configure WebDAV: Enable HTTP on port 5005 and HTTPS on port 5006
  • Control Panel -> File Services -> SMB -> Advanced Settings -> Set min and max SMB protocols to SMB1 and SMB3
  • Create user gituser via Diskstation interface (group users, no access to shared folders, with File Station and WebDAV privilages)
  • Add new shared folder called git (located at /volume1/git) with read/write access for gituser. This folder will hold all the repos.
  • Install Git Server package via Diskstation
  • Open Git Server and allow gituser permissions (one has to login as "admin" to see the available users)
  • Enable SSH access on Diskstation (Control Panel > Terminal & SNMP > Enable SSH Service)
  • Activate user home service (Control Panel > Users > Extended > Userbase > Activate user home service)

Configure SSH Access

  • create ~/.ssh folder for gituser on server
sudo su mkdir /volume1/homes/gituser/.ssh 
  • create a private/public key pair via PuTTYgen (SSH-2 RSA, 2048 bits)
  • copy the public key show at top of the window to a file named authorized_keys
  • copy that file from local computer to gituser account on server
scp authorized_keys username@nas:/volume1/homes/gituser/.ssh 
  • change permissions while logged in as root
cd /volume1/homes/gituser/ sudo chown -R gituser:users .ssh sudo chmod 700 .ssh sudo chmod 644 .ssh/authorized_keys sudo chmod 755 /volume1/homes/gituser 
  • activate public key SSH access by setting the following properties in /etc/ssh/sshd_config
RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile %h/.ssh/authorized_keys 
  • disable and then re-enabled the SSH service (Control Panel > Terminal & SNMP > Enable SSH Service)

Comments

0

I would try the same ssh call without GIT_SSH set

set GIT_SSH= 

With a recent Windows 10, openSSH is either directly installed or provided with Git For Windows.
Make sure to use the latest version of Git, and add its usr/bin folder to your PATH.

1 Comment

Thanks for the tip! This led me to further investigations, which I documented in the original post. Seems that I've to versions of SSH installed, but no matter which one I use: I can always connect to the Git server via SSH, but a git pull always fails :(

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.