connecting to Git via ssh on Windows fails - windows

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 gituser#196.168.0.50
ssh: connect to host 196.168.0.50 port 22: Connection timed out
I updated my Git- and Tortoise installation, now I get
ssh gituser#192.168.0.50
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 gituser#192.168.0.50
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 gituser#192.168.0.50
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?

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)

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".

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.

Related

SSH Permission Denied; Trying to access host in intranet

I know there are several "SHH Permission Denied" questions out there but noting really worked for me.
I am trying to connect to my raspberry pi (Rasbian Butcher) from my PC (Windows 10; Version 1903) using ssh but I get following error:
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug3: Failed to open file:C:/Users/user_name/.ssh/config error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolving "smarthome" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to smarthome [192.168.178.24] port 22.
debug3: finish_connect - ERROR: async io completed with error: 10013, io:0000024AC4D4EAA0
debug1: connect to address 192.168.178.24 port 22: Permission denied
ssh: connect to host host_name port 22: Permission denied
I already tried reseting my firewall to default, to deactivate it, to reinstall ssh server and client on windows.
Does any of you has another idea?
I should add:
-ssh is enabled
-I can access the same raspberry pi with a linux machine on the same network so it must be somehow a win10 probelm

SSH in git behind proxy on windows - FATAL: Connection closed by peer

By a SSH connection, I'm trying to clone a Repository from a Company BitBucket which use 7999 port (not Bitbucket.org) using Git Bash. I've generated the RSA key and added the public key into my profile of the BitBucket Company and the keys re located in ~/.ssh, I've setup the proxy by using git config --global http.proxy http://userPrx:pwdPrx#ipProx:8080 (because I'm under the Company Proxy) and also I have setup my config file as this post suggest. Then, when I try to Test the connection I get this:
$ ssh -vT globaldevtools -p 7999
OpenSSH_7.3p1, OpenSSL 1.0.2j 26 Sep 2016
debug1: Reading configuration data /c/Users/MyUser/.ssh/config
debug1: /c/Users/MyUser/.ssh/config line 5: Applying options for globaldevtools
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: Executing proxy command: exec /C/Users/MyUser/AppData/Local/Programs/Git/mingw64/bin/connect.exe -S IpProxy:8080 x.x.x.x 7999
debug1: permanently_drop_suid: 1104711
debug1: identity file /c/Users/MyUser/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/MyUser/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.3
FATAL: Connection closed by peer.
ssh_exchange_identification: Connection closed by remote host
This is my config file:
ProxyCommand /C/Users/MyUser/AppData/Local/Programs/Git/mingw64/bin/connect.exe -S IpProxy:8080 %h %p
Host globaldevtools
User git
Port 7999
Hostname x.x.x.x
IdentityFile ~/.ssh/id_rsa
TCPKeepAlive yes
IdentitiesOnly yes
I must indicate that in this file (config) instead of IpProxy:8080 I've tried with
http://IpProxy:8080
http://usrProx:pwdProx#IpProxy:8080
usrProx:pwdProx#IpProxy:8080
Do I have to do something else? Did I miss something? All help is appreciated.

SSH config on Windows when working under a HTTP proxy

I'm trying to set up my ~/.ssh/config file to connect on servers through the HTTP proxy my company is using, but it's falling everytime...
Does anyone know how to do this ?
I'm working on Windows 7, using the Git Bash tool, and here is my current ~/.ssh/config:
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa
ProxyCommand connect -H XX.XX.XX.XXXX:8080 %h 443
The command ssh -T git#github.com -v outputs :
OpenSSH_7.1p2, OpenSSL 1.0.2d 9 Jul 2015
debug1: Reading configuration data /c/Users/name/.ssh/config
debug1: /c/Users/name/.ssh/config line 1: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Executing proxy command: exec connect -H XX.XX.XX.XXXX:8080 github.com 443
debug1: permanently_drop_suid: 1201653
debug1: identity file /c/Users/user/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/gregv/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
ssh_exchange_identification: Connection closed by remote host
OK, my problem was actually the port set on 443, here is the correct ~/.ssh/config file file that is working for me :
Host github.com
IdentityFile ~\.ssh\id_rsa
ProxyCommand connect -H XX.XX.XX.XXXX:8080 %h %p
ForwardAgent yes

Connecting to Bitbucket using ssh through proxy

I have run out of options. I have tried several methods but none have worked so I hope someone can help me.
At work we operate behind a proxy; at the moment I am setting a repository that I would like to pull from and push from. I want to this using ssh so I don't need the password at work or when I take the laptop at home.
The repository is created.
I have created an additional distinct ssh key and added it in bitbucket setting profile.
I have loaded the ssh key using the following command - ssh-add ~/.ssh/personal
I have checked and the key is loaded.
when I try to connect to my repository,using clone or any other action(push or pull),it doesn't work
operation timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I have also tried to create a config file in .ssh/ with the following values
Host personalid
HostName bitbucket.org
IdentityFile ~/.ssh/personal
but still it doesn't work
I don't know whether is a proxy issue or something else, I thought ssh should allow me to bypass everything.
Can someone give me an idea on how to diagnose the problem?
Thank you
=========
UPDATE: result of the command ssh -Tv hg#bitbucket.org
ssh -Tv hg#bitbucket.org
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/username/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to bitbucket.org [131.103.20.167] port 22.
debug1: connect to address 131.103.20.167 port 22: Operation timed out
debug1: Connecting to bitbucket.org [131.103.20.168] port 22.
debug1: connect to address 131.103.20.168 port 22: Operation timed out
ssh: connect to host bitbucket.org port 22: Operation timed out
=========
If i use port 443
ssh -Tv -p 443 hg#bitbucket.org
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/username/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to bitbucket.org [131.103.20.167] port 443.
debug1: connect to address 131.103.20.167 port 443: Operation timed out
debug1: Connecting to bitbucket.org [131.103.20.168] port 443.
debug1: connect to address 131.103.20.168 port 443: Operation timed out
ssh: connect to host bitbucket.org port 443: Operation timed out
when trying ssh -Tvp443 hg#altssh.bitbucket.or
ssh -Tvp443 hg#altssh.bitbucket.org
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/username/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to altssh.bitbucket.org [131.103.20.174] port 443.
debug1: connect to address 131.103.20.174 port 443: Operation timed out
ssh: connect to host altssh.bitbucket.org port 443: Operation timed out
The best diagnosis would be to fake an SSH session:
ssh -Tv hg#bitbucket.org
(It doesn't matter whether you're using Git or Mercurial; this test does the same thing either way.)
There'll be a wall of output from the command, thanks to the -v, but the first thing to look for would be a line like this at the end with your specific username:
logged in as cpu2007.
That will establish that a) you're reaching Bitbucket and b) your key is added to your account. If you don't see a line like that, then that should help you diagnose your problem.

Connection reset by peer error using cygwin on windows to connect minix via ssh

i'm using minix on my virtualbox, I was able to connect to minix using putty yesterday, but today everything seems to fail. After this failing I tried to uninstall all the openssh and its etc/ssh directory and reinstall, tried other network adapters, tried using cygwin, and using pscp. But I simply can't connect to minix anymore. Any help would be appreciated.
I'm now using this command on cygwin:
$ ssh -p 3022 -v -v -v root#localhost
and the output is:
OpenSSH_6.3, OpenSSL 1.0.1e 11 Feb 2013
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [::1] port 3022.
debug1: connect to address ::1 port 3022: Connection refused
debug1: Connecting to localhost [127.0.0.1] port 3022.
debug1: Connection established.
debug1: identity file /home/Cem/.ssh/id_rsa type -1
debug1: identity file /home/Cem/.ssh/id_rsa-cert type -1
debug1: identity file /home/Cem/.ssh/id_dsa type -1
debug1: identity file /home/Cem/.ssh/id_dsa-cert type -1
debug1: identity file /home/Cem/.ssh/id_ecdsa type -1
debug1: identity file /home/Cem/.ssh/id_ecdsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.3
ssh_exchange_identification: read: Connection reset by peer
You have to allow connections within your own subnet in the Cygwin /etc/hosts.allow. Add a line like this to your /etc/hosts.allow on the Cygwin machine:
ALL : 192.168.123.0/24 : allow
and in your case, you'll need to add the localhost like so:
ALL : localhost 127.0.0.1/32 [::1]/128 [::ffff:127.0.0.1]/128 : allow
The last line should have come with a stock Cygwin installation so it would be strange if you had to add it.
It matters where you enter it. You will have some DENY entries and you should put it above those, but it should work if you put it with all of the other ALLOW statements.

Resources