成功登录后Linux关闭连接


23

我正在使用Debian 5.2.2在服务器上工作。几乎不具备Linux的管理知识,我想我搞砸了。我使用apt-get更新和apt-get升级来更新所有内容,然后下载并安装了Apache,PHP和MySQL。这些工具似乎工作正常,但现在我什至无法通过本地控制台登录服务器。如果我尝试通过GUI登录,或者尝试通过ssh,scp或其他方式远程登录,则成功登录后会立即断开连接。换句话说,初始连接没有问题,但是当我输入正确的用户名和密码(对于root或任何用户)时,我断开了连接。使用GUI,屏幕会变黑一秒钟,然后将我带回到登录提示。使用ssh,我可以“关闭与[服务器]的连接”。

感谢您的帮助,如果有任何办法可以提供更多信息,请告诉我。感谢您的时间。

编辑:

-任何用户都可以在本地控制台上登录

-目前我没有本地访问计算机的权限,所以我现在所能做的就是ssh。输入密码后,这是ssh -vvv [server]的输出:

Linux xxxxxxx.com 2.6.26.8+20091222+1056-debhawk-5.2.2-custom #1 SMP PREEMPT Tue Dec 22 10:58:57 EST 2009 i686

Last login: Mon Apr 30 14:48:07 2012 from xxxxxxx.com
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
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug2: channel 0: rcvd close
debug2: channel 0: close_read
debug2: channel 0: input open -> closed
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
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)

debug3: channel 0: close_fds r -1 w -1 e 6
Connection to xxx.x.xx.xx closed.
debug1: Transferred: stdin 0, stdout 0, stderr 35 bytes in 0.0 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 3845.3
debug1: Exit status 254

5
Linux是内核,而不是操作系统。没有内核版本5.2.2,那么您使用的是哪个发行版?
斯文

2
通过控制台登录,/var/log/messages/car/log/secure在尝试远程登录时检查和日志。尝试使用登录,ssh -vvv <servername>这样您可以查看出什么问题了。 dmesg输出可能也很有用,但您只需要修剪和发布相关的部分。您可以使用本地控制台上的任何用户帐户登录还是只能以root用户登录?SSH守护程序是否正在运行(ps auxwww|grep ssh)?
布拉姆2012年

Answers:


24

有几个类似的帖子表明,由于不正确的shell路径设置,这可能是生成shell的问题。 /etc/passwd

要检查这一点,请确定您的用户外壳程序路径存在并且可执行。

# cat /etc/passwd | grep tomh
tomh:x:1000:1000:Tom H:/home/tomh:/bin/bash <-- check this exists

检查外壳是否存在:

# file /bin/bash
/bin/bash: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, stripped

另外,请检查外壳程序是否未设置为/sbin/nologin/bin/false,即使成功进行身份验证,也不会阻止登录。

http://www.linuxforums.org/forum/ubuntu-linux/173779-solved-ssh-issue.html
http://www.unix.com/hp-ux/169496-solved-ssh-debug1-exit-status -254-problem.html
http://www.mail-archive.com/seawolf-list@redhat.com/msg04460.html


这确实是我的问题,对于全新的cygwin安装,安装创建的用户的用户路径应为/ bin / false。将其更改为/ bin / bash可解决此问题。谢谢!
米奇·肯特

1
以我的经验,在创建用户时指定shell是明智的。默认设置因dist而异。
MetalGodwin '16

4

当我遇到这样的问题时,我仍然打开了一个连接/ var / log / messages:

pam_loginuid(sshd:session): Cannot open /proc/self/loginuid: Read-only file system

编辑vi /etc/init.d/named可以更改/ proc的安装方式,因此重新启动后不会出现该错误。

基本上线条

if [ ! -e "${CHROOT_PREFIX}/proc/meminfo" ]; then
mkdir -p “${CHROOT_PREFIX}/proc”
        mount -tproc -oro,nosuid,nodev,noexec proc ${CHROOT_PREFIX}/proc 2>/dev/null
fi;

改为

if [ ! -e "${CHROOT_PREFIX}/proc/meminfo" ]; then
mkdir -p “${CHROOT_PREFIX}/proc”
        mount –bind -o ro /proc “${CHROOT_PREFIX}/proc” 2>/dev/null
fi;

我在http://www.computersalat.de/linux/strato-vserver/ssh-login-problem-nach-neustart/#comment-905中找到的提示


欢迎来到顺丰。您可以通过将代码缩进4个空格(或在其周围使用反引号)来改善答案的样式。
ℝaphink

在使用systemd而不是SysV的CentOS 7上相当于什么?
史蒂夫·乔根森

4

我的问题是登录用户名目录在目录中不可用/home。因此,如果您有一个名为“ testuser”的用户,请确保该/home/testuser目录可用。从/var/log/messages文件中得知。


绝对检查的/var/log/messages/auth.log指针。也有文件问题
Nick

3
debug3: channel 0: close_fds r -1 w -1 e 6
Connection to xxx.x.xx.xx closed.
debug1: Transferred: stdin 0, stdout 0, stderr 35 bytes in 0.0 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 3845.3
debug1: Exit status 254

在SSH服务器的sshd_config文件中,添加以下行:

UsePAM no

下面是sshd_config我在OS X上使用的代码。我将其发布(而不是在Debian机器上发布),因为我在使用Macports(而不是Debian)的OS X上遇到了相同的问题。

AddressFamily any
ListenAddress 0.0.0.0
Port 1522

# The default requires explicit activation of protocol 1
Protocol 2

# HostKeys for protocol version 2
HostKey /opt/local/etc/ssh/ssh_host_ed25519_key
HostKey /opt/local/etc/ssh/ssh_host_ecdsa_key
HostKey /opt/local/etc/ssh/ssh_host_rsa_key
HostKey /opt/local/etc/ssh/ssh_host_dsa_key

# Ciphers and keying
#RekeyLimit default none

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

# User Authentication

PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
UsePAM no

# 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

# Use sandbox on OS X
UsePrivilegeSeparation sandbox

# All user's environment
PermitUserEnvironment yes

# no default banner path
#Banner none

# override default of no subsystems
Subsystem   sftp    /opt/local/libexec/sftp-server

1
UsePAM =是,这是我的centos7 / i686 LXD图像中的问题。一旦设置为“ no”,ssh登录将再次起作用。但是,sshd_config中有一条注释:“警告:Red Hat Enterprise Linux不支持'UsePAM no',这可能会导致一些问题。” 如果有人知道这到底意味着什么,请说明一下。
ILIV

当我尝试更改为UsePAM = no时,即使我应该使用RSA密钥进行身份验证,也要求我输入密码。
史蒂夫·乔根森

2

如果您使用的是LDAP,请替换以下所有情况:

pam_unix_*.so

在/etc/pam.d/中的所有文件中,带有:

pam_unix.so

这是libpam-ldap软件包中的错误(示例pam.d文件),请参阅:http ://bugs.debian.org/cgi-bin/bugreport.cgi?bug= 612825

确保系统可以正确解析,ssh对此有些特殊。

检查/etc/secuiry/limits.conf以查看是否有任何帐户对登录数量有硬限制并增加这些限制,即:

*       hard    maxlogins   0

除了Bram提到的/ var / log / messages,还请检查/var/log/auth.log并粘贴任何相关输出。信息多于少。


1

我确实确实遇到了@ tom-h之前建议的方式中的这些症状……而且解决方法非常简单。

要解决此问题,只需简单地vipw编辑passwd文件,将shell从/ bin / false调整为/ bin / bash或您的首选项即可。

# cat /etc/passwd | grep adamjohn
adamjohn:x:1000:1000:Adam John:/home/adamjohn:/bin/false <-- check this exists
# vi /etc/passwd
adamjohn:x:1000:1000:Adam John:/home/adamjohn:/bin/bash <-- change this item

请理解,在某些情况下可能会这样做是为了保护敏感帐户。可能还有其他访问限制。您应该了解保护服务器的重要性,并了解允许这种类型的访问服务器的含义。


1

我在使用LDAP的Ubuntu 16.04时遇到了类似的问题。“ ssh -vv ...”显示密码身份验证成功,但随后出现消息:“与...的连接被远程主机关闭。”

已在“ / bind_policy”配置中的/etc/ldap.conf中修复。

/var/log/auth.log显示:

sshd[19884]: Accepted password for xxxx from xx.xx.xx.xx port 48426 ssh2
sshd[19884]: pam_unix(sshd:session): session opened for user xxxx by (uid=0)
systemd-logind[577]: New session 22 of user xxxx.
systemd: pam_unix(systemd-user:session): session opened for user xxxx by (uid=0)
sshd[19884]: nss_ldap: could not search LDAP server - Server is unavailable
sshd[19884]: fatal: login_get_lastlog: Cannot find account for uid 1502 
sshd[19884]: pam_unix(sshd:session):   session closed for user xxxx

发现问题出在/etc/ldap.conf中。我将bind_policy更改为“ soft”,因此nss_ldap在服务器故障时立即返回。默认值为“ hard_open”,如果打开与LDAP服务器的连接失败,它将重新连接。注释掉“ bind_policy soft”行将其更改回默认值,并解决了问题。:-)



0

所有这些都是很好的建议。在我的情况下,是腻子的设置导致了我的痛苦:

我已将远程命令发送到“ SSH”配置下的服务器。这在99%的时间内都有效,但是,当命令失败时,它将关闭会话。

命令???屏幕-rd

当实际上有一个会话要恢复时,效果很好。重新启动后严重失败。

解决方案:

将其移动到bashrc / bash_profile。


0

就我而言,这是由SSH服务器上没有外壳的用户引起的。它的修复非常简单,只需在-N(Open)SSH客户端上使用该开关即可。

手册页

-N 不执行远程命令。这对于仅转发端口很有用。

我只是不同意这里的一些答案。与所述外壳中的用户/bin/false/bin/nologin是一种适当的配置,它通常仅用于对SSH隧道使用的用户,而不可能性登录和SSH服务器上执行的任何命令。因此,请勿尝试在服务器上“修复”它,只需将-N开关与SSH客户端一起使用即可。


0

确保/etc/passwd为用户安装了正确的外壳。

例如,ahmad由于缺少外壳,用户无法登录服务器:

ahmad:x:10000:1003::/home/ahmad:/bin/false

由于shell设置/bin/false它意味着用户ahmad不具有外壳,并解决这个问题,你必须改变/bin/false,以/bin/bash对于bash或任何其他壳。

如果您使用的是Web托管控制面板(例如Plesk),请确保用户具有访问服务器的能力。


-1

可能是LDAP问题。无需配置即可运行用于配置LDAP,Kerberos和SMB设置的authconfig,

--enablemkhomedir


你好,请尝试回答其他问题:关于Debian 5 OP会谈,完全过时的生产
bgtvfr
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.