Cygwin OpenSSH 在连接后立即关闭

Cygwin OpenSSH 在连接后立即关闭

尝试使用 putty 或 cygwin ssh 在 localhost 上连接到 cygwin-sshd,我得到的结果如下。我在另一台 Win7x64 机器上运行良好,但这台机器却很糟糕。两台机器的配置文件相同。

Putty 告诉我这个:

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 为我打印出这个:

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

但出于某种原因,它无法保持连接?我该如何解决这个问题?

这是 SSH 配置文件:

#   $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

这是 SSHD 配置文件:

#   $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

我没有在这两个文件中看到任何可以解释这个问题的内容。它们也与我的工作环境相同。

答案1

由于某种原因,当我遇到同样的问题时,这对我有用:

ssh 127.0.0.1 /bin/bash

但如果问题出在 bash 上,那么也会发生同样的事情。所以如果这不起作用,您可以通过尝试运行任何命令来了解更多信息,例如:

ssh 127.0.0.1 ls

另请参见此处:

https://serverfault.com/questions/384676/linux-closing-connection-after-successful-login

由于 Cygwin 在 Windows 上运行,这可能是由于在 \n 之前按 Enter 键输入 \r,这意味着“\r”将是您要运行的命令而不是 /bin/bash,因此它将 \r 作为 bash 脚本运行并退出。我只在 Windows 8 上使用 Cygwin 时遇到过这种情况。

答案2

如果我没记错的话,在 Linux 上,如果您尝试登录的帐户的指定 shell 是/bin/false,就会发生这种情况或类似的事情,这是一种阻止帐户通过 shell 执行任何操作的方法。

我不知道 Cygwin 是否sshd会检查/etc/passwd要生成什么 shell,但也许会检查该文件并查看您的帐户是否列出,或者chsh从控制台尝试并指定/bin/bash或类似于 shell。

相关内容