Cygwin OpenSSH closes immediately after a connection
Solution 1
For some reason this worked for me when I had the same problem:
ssh 127.0.0.1 /bin/bash
But if bash is the problem, the same thing would happen. so if that doesn't work, you might learn more by just trying to run any command, e.g.:
ssh 127.0.0.1 ls
Also see here:
https://serverfault.com/questions/384676/linux-closing-connection-after-successful-login
Since Cygwin runs on Windows, it could be due to the enter key typing \r before the \n, meaning "\r" would be the command you're trying to run instead of /bin/bash, so it runs \r as bash script and exits. I am only experiencing this using Cygwin on Windows 8.
Solution 2
If I'm not mistaken, on Linux, this or something similar can happen if the specified shell for the account you're trying to log into is /bin/false
, which is a way to prevent an account from being able to do anything via a shell.
I don't know if Cygwin's sshd
checks /etc/passwd
to find out what shell to spawn but maybe check that file and see if your account is listed, or try chsh
from the console and specify /bin/bash
or similar as the shell.
Related videos on Youtube
Momshad Dinuri Alvee
Started writing code in 1982 (in college) and haven't stopped since. I've used C++ to build applications for Libraries (the kind that lend books) and Banks and sleep labs. I've also written Java for banks. Worked with Pyramid in Grand Cayman for Uniregistry. Been working with Django since 2009 and have used it to build solutions for banks, sleep labs, and ALS clinics. Built a labor scheduling tool for the entertainment industry that uses AngularJS for the frontend SPA and Django rest framework for the back end API and DJango views for reports. I've been the rescue engineer for 911 calls that were getting lost, SQL queries that were so slow the application was timing them out, and written various scripts to patch around otherwise broken software packages where the source code was not available. A long time ago, in a galaxy far far away I wrote kernel code for Unix SYSV in the ethernet/FDDI arena for Intergraph.
Updated on September 18, 2022Comments
-
Momshad Dinuri Alvee over 1 year
Trying to connect to cygwin-sshd using putty or cygwin ssh on localhost, here is all I get. I have it working fine on a different Win7x64 machine but this one is proving hellish. Config files for both machines are identical.
Putty tells me this:
2013-03-08 14:36:16 Connecting to 127.0.0.1 port 22 2013-03-08 14:36:16 Server version: SSH-2.0-OpenSSH_6.1 2013-03-08 14:36:16 Using SSH protocol version 2 2013-03-08 14:36:16 We claim version: SSH-2.0-PuTTY_Release_0.62 2013-03-08 14:36:16 Doing Diffie-Hellman group exchange 2013-03-08 14:36:16 Doing Diffie-Hellman key exchange with hash SHA-256 2013-03-08 14:36:16 Host key fingerprint is: 2013-03-08 14:36:16 ssh-rsa 2048 48:e0:21:ce:d7:bc:85:b4:f7:3e:49:08:31:4d:55:5a 2013-03-08 14:36:16 Initialised AES-256 SDCTR client->server encryption 2013-03-08 14:36:16 Initialised HMAC-SHA1 client->server MAC algorithm 2013-03-08 14:36:16 Initialised AES-256 SDCTR server->client encryption 2013-03-08 14:36:16 Initialised HMAC-SHA1 server->client MAC algorithm 2013-03-08 14:36:18 Attempting keyboard-interactive authentication 2013-03-08 14:36:18 Server refused keyboard-interactive authentication 2013-03-08 14:36:21 Sent password 2013-03-08 14:36:21 Access granted 2013-03-08 14:36:21 Opened channel for session 2013-03-08 14:36:21 Allocated pty (ospeed 38400bps, ispeed 38400bps) 2013-03-08 14:36:21 Started a shell/command 2013-03-08 14:36:21 Server sent command exit status 0 2013-03-08 14:36:43 Disconnected: All channels closed
sshd -ddd prints this out for me:
login as: username [email protected]'s password: Last login: Fri Mar 8 14:36:21 2013 from 127.0.0.1 debug1: permanently_set_uid: 11625/10513 debug3: Copy environment: ALLUSERSPROFILE=C:\\ProgramData debug3: Copy environment: COMPUTERNAME=QTEC0611 debug3: Copy environment: COMSPEC=C:\\Windows\\system32\\cmd.exe debug3: Copy environment: OS=Windows_NT debug3: Copy environment: PATH=/cygdrive/c/Program Files/Common Files/Microsoft Shared/Windows Live:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files/NTRU Cryptosystems/NTRU TCG Software Stack/bin:/cygdrive/c/Program Files/Wave Systems Corp/Gemalto/Access Client/v5:/cygdrive/c/Program Files/Common Files/Roxio Shared/DLLShared:/cygdrive/c/Program Files/Common Files/Roxio Shared/10.0/DLLShared:/cygdrive/c/Program Files/ActivIdentity/ActivClient:/cygdrive/c/Program Files/Windows Live/Shared:/cygdrive/c/Program Files/QuickTime/QTSystem:/cygdrive/c/Program Files/Microsoft SQL Server/110/Tools/Binn:/cygdrive/c/Program Files/Microsoft SQL Server/110/DTS/Binn:/cygdrive/c/Cygwin/bin:/cygdrive/c/Program Files/PuTTY:/bin debug3: Copy environment: PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC debug3: Copy environment: PROGRAMFILES=C:\\Program Files debug3: Copy environment: SYSTEMDRIVE=C: debug3: Copy environment: SYSTEMROOT=C:\\Windows debug3: Copy environment: WINDIR=C:\\Windows Environment: ALLUSERSPROFILE=C:\ProgramData COMPUTERNAME=QTEC0611 COMSPEC=C:\Windows\system32\cmd.exe OS=Windows_NT PATH=/cygdrive/c/Program Files/Common Files/Microsoft Shared/Windows Live:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerSh PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC PROGRAMFILES=C:\Program Files SYSTEMDRIVE=C: SYSTEMROOT=C:\Windows WINDIR=C:\Windows USER=username LOGNAME=username HOME=/home/username MAIL=/var/spool/mail//username SHELL=/bin/bash SSH_CLIENT=127.0.0.1 52075 22 SSH_CONNECTION=127.0.0.1 52075 127.0.0.1 22 SSH_TTY=/dev/pty1 TERM=xterm
But for some reason won't let it stay connected? How do I troubleshoot this?
Here is the SSH config file:
# $OpenBSD: ssh_config,v 1.26 2010/01/11 01:39:46 dtucker Exp $ # This is the ssh client system-wide configuration file. See # ssh_config(5) for more information. This file provides defaults for # users, and the values can be changed in per-user configuration files # or on the command line. # Configuration data is parsed as follows: # 1. command line options # 2. user-specific file # 3. system-wide file # Any configuration value is only changed the first time it is set. # Thus, host-specific definitions should be at the beginning of the # configuration file, and defaults at the end. # Site-wide defaults for some commonly used options. For a comprehensive # list of available options, their meanings and defaults, please see the # ssh_config(5) man page. # Host * # ForwardAgent no # ForwardX11 no # RhostsRSAAuthentication no # RSAAuthentication yes # PasswordAuthentication yes # HostbasedAuthentication no # GSSAPIAuthentication no # GSSAPIDelegateCredentials no # BatchMode no # CheckHostIP yes # AddressFamily any # ConnectTimeout 0 # StrictHostKeyChecking ask # IdentityFile ~/.ssh/identity # IdentityFile ~/.ssh/id_rsa # IdentityFile ~/.ssh/id_dsa # Port 22 # Protocol 2,1 # Cipher 3des # Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc # MACs hmac-md5,hmac-sha1,[email protected],hmac-ripemd160 # EscapeChar ~ # Tunnel no # TunnelDevice any:any # PermitLocalCommand no # VisualHostKey no # ProxyCommand ssh -q -W %h:%p gateway.example.com
Here is the SSHD config file:
# $OpenBSD: sshd_config,v 1.87 2012/07/10 02:19:15 djm Exp $ # This is the sshd server system-wide configuration file. See # sshd_config(5) for more information. # This sshd was compiled with PATH=/bin:/usr/sbin:/sbin:/usr/bin # The strategy used for options in the default sshd_config shipped with # OpenSSH is to specify options with their default value where # possible, but leave them commented. Uncommented options override the # default value. Port 22 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress :: # The default requires explicit activation of protocol 1 #Protocol 2 # HostKey for protocol version 1 #HostKey /etc/ssh_host_key # HostKeys for protocol version 2 #HostKey /etc/ssh_host_rsa_key #HostKey /etc/ssh_host_dsa_key #HostKey /etc/ssh_host_ecdsa_key # Lifetime and size of ephemeral version 1 server key #KeyRegenerationInterval 1h #ServerKeyBits 1024 # Logging # obsoletes QuietMode and FascistLogging #SyslogFacility AUTH #LogLevel INFO # Authentication: #LoginGraceTime 2m #PermitRootLogin yes StrictModes no #MaxAuthTries 6 #MaxSessions 10 #RSAAuthentication yes #PubkeyAuthentication yes # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 # but this is overridden so installations will only check .ssh/authorized_keys AuthorizedKeysFile .ssh/authorized_keys #AuthorizedPrincipalsFile none # For this to work you will also need host keys in /etc/ssh_known_hosts #RhostsRSAAuthentication no # similar for protocol version 2 #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for # RhostsRSAAuthentication and HostbasedAuthentication #IgnoreUserKnownHosts no # Don't read the user's ~/.rhosts and ~/.shosts files #IgnoreRhosts yes # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes # Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes #KerberosGetAFSToken no # GSSAPI options #GSSAPIAuthentication no #GSSAPICleanupCredentials yes # Set this to 'yes' to enable PAM authentication, account processing, # and session processing. If this is enabled, PAM authentication will # be allowed through the ChallengeResponseAuthentication and # PasswordAuthentication. Depending on your PAM configuration, # PAM authentication via ChallengeResponseAuthentication may bypass # the setting of "PermitRootLogin without-password". # If you just want the PAM account and session checks to run without # PAM authentication, then enable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'. #UsePAM no #AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no #X11Forwarding no #X11DisplayOffset 10 #X11UseLocalhost yes #PrintMotd yes #PrintLastLog yes #TCPKeepAlive yes #UseLogin no UsePrivilegeSeparation sandbox # Default for new installations. #PermitUserEnvironment no #Compression delayed #ClientAliveInterval 0 #ClientAliveCountMax 3 #UseDNS yes #PidFile /var/run/sshd.pid #MaxStartups 10 #PermitTunnel no #ChrootDirectory none #VersionAddendum none # no default banner path #Banner none # override default of no subsystems Subsystem sftp /usr/sbin/sftp-server # Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # ForceCommand cvs server
I don't see anything in either of these files to account for the problem. They are identical to my working environment as well.
-
sbtkd85 about 11 yearsCan you get it working without SSH keys? As in manually authenticate by typing in your username & password? Seems like it might be an issue with how the keyed authentication is working based on a quick look at these logs.
-
Momshad Dinuri Alvee about 11 yearsHaven't got it working with keys yet, this is using username/pw. Connection closes right after it accepts the password.
-
sbtkd85 about 11 yearsIn that case, I think your settings on the server might need checking. I see "Server refused keyboard-interactive authentication" and think that somehow manual authentication has been disabled.
-