Discussion:
SSH Closes Immediately After Opening
(too old to reply)
Wallace Forman
2016-06-29 16:24:55 UTC
Permalink
Hello there,

I am having trouble connecting to a ssh server installed with openssh
recently. I have posted about the problem on Superuser, and I will repost a
description of the issue below. If anyone here is able to rescue me from my
deep well of ignorance, I will be very grateful.

http://superuser.com/questions/1094734/ssh-automatically-disconnects-after-login

I'm trying to set up an ssh server using OpenSSH on Windows 10. On one of
my computers, I've been able to set up the server and successfully login
from the same machine.

On the other computer, the SSH session seems to be terminating immediately,
despite having the same default settings in a similar Windows 10 system.

After logging in from the command prompt with ssh -vvv localhost, here is
the information displayed after the password has been entered:

debug3: send packet: type 50
debug2: we sent a password packet, wait for reply
debug3: receive packet: type 52
debug1: Authentication succeeded (password).
Authenticated to localhost ([::1]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Requesting no-more-***@openssh.com
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: network
debug3: receive packet: type 80
debug1: client_input_global_request: rtype hostkeys-***@openssh.com want_reply 0
debug3: receive packet: type 91
debug2: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: ssh_packet_set_tos: set IPV6_TCLASS 0x10
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug3: send packet: type 98
debug2: channel 0: request shell confirm 1
debug3: send packet: type 98
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype ***@openssh.com reply 0
debug2: channel 0: rcvd eow
debug2: channel 0: close_read
debug2: channel 0: input open -> closed
debug3: receive packet: type 96
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug3: receive packet: type 97
debug2: channel 0: rcvd close
debug3: channel 0: will not send data after close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug3: send packet: type 97
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
#0 client-session (t4 r0 i3/0 o3/0 fd -1/-1 cc -1)

debug3: send packet: type 1
Connection to localhost closed.
Transferred: sent 2168, received 4052 bytes, in 0.9 seconds
Bytes per second: sent 2501.0, received 4674.3
debug1: Exit status 255

Here are the sshd_config settings:

# $OpenBSD: sshd_config,v 1.98 2016/02/17 05:29:04 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 change a
# 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
#HostKey /etc/ssh_host_ed25519_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Ciphers and keying
#RekeyLimit default none

# Logging
#obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
LogLevel DEBUG3

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
#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

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/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 yes
# 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
#GSSAPICleanupCreds 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
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
UsePrivilegeSeparation no
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# default banner path
Banner /etc/banner.txt

# 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
# PermitTTY no
# ForceCommand cvs server

I've seen a few posts suggesting that I turn on logging
<http://unix.stackexchange.com/questions/166975/ssh-connection-to-server-closed-after-authentication-immediately>
to
get more information. However, I can't figure out how to accomplish this.
None of the log files that appear in C:\Program Files\OpenSSH\var\loghave
any information, and I can't figure out where the logs might be, or how
else to enable them.

Let me know if you have any suggestions how to solve my problem or at least
to enable logging. Thanks!
Scott Neugroschl
2016-06-29 16:48:06 UTC
Permalink
You can turn on server logging with the -ddd option. This will run the server in the foreground and send debug output to stderr

-----Original Message-----
From: openssh-unix-dev [mailto:openssh-unix-dev-bounces+scott_n=***@mindrot.org] On Behalf Of Wallace Forman
Sent: Wednesday, June 29, 2016 9:25 AM
To: openssh-unix-***@mindrot.org
Subject: SSH Closes Immediately After Opening

Hello there,

I am having trouble connecting to a ssh server installed with openssh recently. I have posted about the problem on Superuser, and I will repost a description of the issue below. If anyone here is able to rescue me from my deep well of ignorance, I will be very grateful.

http://superuser.com/questions/1094734/ssh-automatically-disconnects-after-login

I'm trying to set up an ssh server using OpenSSH on Windows 10. On one of my computers, I've been able to set up the server and successfully login from the same machine.

On the other computer, the SSH session seems to be terminating immediately, despite having the same default settings in a similar Windows 10 system.

After logging in from the command prompt with ssh -vvv localhost, here is the information displayed after the password has been entered:
[redacted]


I've seen a few posts suggesting that I turn on logging <http://unix.stackexchange.com/questions/166975/ssh-connection-to-server-closed-after-authentication-immediately>
to
get more information. However, I can't figure out how to accomplish this.
None of the log files that appear in C:\Program Files\OpenSSH\var\loghave any information, and I can't figure out where the logs might be, or how else to enable them.

Let me know if you have any suggestions how to solve my problem or at least to enable logging. Thanks!
Ángel González
2016-06-29 18:48:46 UTC
Permalink
Post by Wallace Forman
Let me know if you have any suggestions how to solve my problem or at least
to enable logging. Thanks!
Does the user that is trying to login have a shell that sshd will be
able to run?
Wallace Forman
2016-06-29 19:36:08 UTC
Permalink
Hmm... Perhaps not. Is something like cygwin required for it to work?

Wallace Forman
913-669-4453
Post by Wallace Forman
Let me know if you have any suggestions how to solve my problem or at
least
to enable logging. Thanks!
Does the user that is trying to login have a shell that sshd will be able
to run?
Ángel González
2016-06-29 20:37:24 UTC
Permalink
Post by Wallace Forman
Hmm... Perhaps not. Is something like cygwin required for it to work?
Where did you install OpenSSH from?
cygwin is an avenue for running openssh in Windows, but
I don't think it supports native Windows out-of-the box
(someone else on the list will surely correct me if I'm wrong).

Regards
Wallace Forman
2016-06-29 20:57:14 UTC
Permalink
I used the latest version from here:

http://www.mls-software.com/opensshd.html

On my other (Windows 10) machine (on which openssh works), I have cygwin
installed, but if ssh was using cygwin, I wasn't aware of it. I just ran
ssh from the command prompt.

Wallace Forman
913-669-4453
Post by Wallace Forman
Hmm... Perhaps not. Is something like cygwin required for it to work?
Where did you install OpenSSH from?
cygwin is an avenue for running openssh in Windows, but
I don't think it supports native Windows out-of-the box
(someone else on the list will surely correct me if I'm wrong).
Regards
Ángel González
2016-06-29 21:35:33 UTC
Permalink
Post by Wallace Forman
http://www.mls-software.com/opensshd.html
On my other (Windows 10) machine (on which openssh works), I have
cygwin installed, but if ssh was using cygwin, I wasn't aware of it. I
just ran ssh from the command prompt.
Wallace Forman
Yes, that ssh server is cygwin-based. It is however including the basic
cygwin files it needs, so the fact that it actually doesn't work without
a normal cygwin install seems a bug in the package.


Regards
Hisashi T Fujinaka
2016-06-30 03:23:27 UTC
Permalink
Post by Ángel González
Post by Wallace Forman
http://www.mls-software.com/opensshd.html
On my other (Windows 10) machine (on which openssh works), I have cygwin
installed, but if ssh was using cygwin, I wasn't aware of it. I just ran
ssh from the command prompt.
Wallace Forman
Yes, that ssh server is cygwin-based. It is however including the basic
cygwin files it needs, so the fact that it actually doesn't work without a
normal cygwin install seems a bug in the package.
I wasn't really paying attention but the first thing I thought of was
this sounds like the problem I usually see when my shell is broken. Can
you log into the account using the console?
--
Hisashi T Fujinaka - ***@twofifty.com
BSEE + BSChem + BAEnglish + MSCS + $2.50 = coffee
Corinna Vinschen
2016-06-30 14:39:11 UTC
Permalink
Post by Ángel González
Post by Wallace Forman
http://www.mls-software.com/opensshd.html
On my other (Windows 10) machine (on which openssh works), I have cygwin
installed, but if ssh was using cygwin, I wasn't aware of it. I just ran
ssh from the command prompt.
Wallace Forman
Yes, that ssh server is cygwin-based. It is however including the basic
cygwin files it needs, so the fact that it actually doesn't work without a
normal cygwin install seems a bug in the package.
Using the orignal Cygwin distro OpenSSH instead of some arbitrary 3rd
party package fixes this.


Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
Wallace Forman
2016-06-30 15:12:17 UTC
Permalink
Embarrassing to say, I'm really not sure what constitutes a "console" or
"shell". To explain what does and does not seem to be working:

1) I have two windows computers on the same wireless network, both with
openssh for windows installed from the link previously sent.

2) On computer 1, sshd is running, but when connecting with "ssh localhost"
from the command prompt on that same computer, sshd seems to be accepting
the password, but closing immediately (see output in previous messages).

3) On computer 2, sshd runs, and I can connect on that computer from the
command prompt or from putty.

4) When I try to connect from computer 2 to computer 1 (from putty or
command prompt), the session closes immediately, as when I try to connect
from Computer 1.

5) Also, Computer 2 does not seem to be accepting the password input from
computer 1. Haven't really tried to troubleshoot this yet, perhaps this is
an sshd_config issue.

Wallace Forman
913-669-4453
Post by Hisashi T Fujinaka
Post by Ángel González
Post by Wallace Forman
http://www.mls-software.com/opensshd.html
On my other (Windows 10) machine (on which openssh works), I have cygwin
installed, but if ssh was using cygwin, I wasn't aware of it. I just ran
ssh from the command prompt.
Wallace Forman
Yes, that ssh server is cygwin-based. It is however including the basic
cygwin files it needs, so the fact that it actually doesn't work without a
normal cygwin install seems a bug in the package.
I wasn't really paying attention but the first thing I thought of was
this sounds like the problem I usually see when my shell is broken. Can
you log into the account using the console?
--
BSEE + BSChem + BAEnglish + MSCS + $2.50 = coffee
Ángel González
2016-06-30 21:45:18 UTC
Permalink
Post by Wallace Forman
Embarrassing to say, I'm really not sure what constitutes a "console"
or "shell".
The shell is the program that reads the commands you write and executes
them.
ssh doesn't run "cd" It handles the secure layer, launches your shell
and leaves you to communicate with it however you want. So for instance
if your shell is cmd.exe you would list the contents of a folder with
"dir", but use "ls" in bash.

If after authentication sshd is not able to run your shell (errors
reading the user profile, the shell is not executable, etc.), then it
closes the connection, as you report.
Post by Wallace Forman
(…)
2) On computer 1, sshd is running, but when connecting with "ssh
localhost" from the command prompt on that same computer, sshd seems
to be accepting the password, but closing immediately (see output in
previous messages).
You can verify whether it is really accepting the password by entering a
wrong one.
Post by Wallace Forman
4) When I try to connect from computer 2 to computer 1 (from putty or
command prompt), the session closes immediately, as when I try to
connect from Computer 1.
This is the same as #2


Regards
Wallace Forman
2016-07-01 16:18:14 UTC
Permalink
Thanks all for the responses. I was able to get ssh working with cygwin.

Wallace Forman
913-669-4453
Post by Wallace Forman
Embarrassing to say, I'm really not sure what constitutes a "console" or
"shell".
The shell is the program that reads the commands you write and executes
them.
ssh doesn't run "cd" It handles the secure layer, launches your shell and
leaves you to communicate with it however you want. So for instance if your
shell is cmd.exe you would list the contents of a folder with "dir", but
use "ls" in bash.
If after authentication sshd is not able to run your shell (errors reading
the user profile, the shell is not executable, etc.), then it closes the
connection, as you report.
(…)
2) On computer 1, sshd is running, but when connecting with "ssh
localhost" from the command prompt on that same computer, sshd seems to be
accepting the password, but closing immediately (see output in previous
messages).
You can verify whether it is really accepting the password by entering a
wrong one.
4) When I try to connect from computer 2 to computer 1 (from putty or
command prompt), the session closes immediately, as when I try to connect
from Computer 1.
This is the same as #2
Regards
Loading...