Linux 用户无法登录

Linux 用户无法登录

我正在尝试使用useraddroot 凭据使用命令创建新用户,它已正确创建,但是当我使用 PuTTY 控制台使用新创建的用户及其凭据登录时,我可以输入用户名,但当我提供密码时,它挂起很长时间,直到发生 PuTTY 窗口会话超时并关闭窗口。但是,当我使用 root 凭据时,它会快速进入会话。

我尝试检查AllowUsers下文件/etc/ssh/sshd_config,但没有找到任何匹配的条目,因此,我手动尝试添加我创建的用户名在AllowUsers temipuser哪里。temipuser从另一个 PuTTY 控制台进行此更改后,我再次尝试输入此用户名,但它又是相同的。我完全不知道为什么会发生这种情况。

另一件事是,如果我将任何用户(例如 )添加到文件中的条目temipuser中,root 用户是否仍然具有访问权限或无法访问?我不想把这里的事情搞砸。据我所知,只允许指定的用户并拒绝其他用户。AllowUserssshd_configAllowUsers

答案1

/var/log/secure在或下查找任何相关条目/var/log/auth.log。另外,请确保您没有添加/etc/security/access.conf可能会访问该用户的服务器的自定义规则。

这些日志将包含有关登录失败的信息,并可能清楚地表明出了什么问题。

/etc/security/access.conf文件指定接受或拒绝登录的(用户/组、主机)、(用户/组、网络/网络掩码)或(用户/组、tty)组合。

答案2

接下来,在 Linux 计算机上添加用户后,您还必须为该用户生成密钥(协议类型 2,最好是 RSA)。您可以使用 Putty 的密钥生成器找到相关说明这里

选择 putty 密钥生成器中“用于粘贴到authorized_keys 文件中的公钥”框中的所有文本,将其粘贴到文本编辑器中并以名称保存authorized_keys

在 Linux 计算机上新用户的主目录中,.ssh如果不存在则创建一个目录。此目录应由用户拥有,并且只有该用户有权访问它 ( chmod 700 .ssh) 将authorized_keys文件复制到此目录。您应该使用 更改该文件的权限chmod 0600,并将所有权更改为用户。

现在用户应该能够登录。

答案3

在尝试这些命令之前,您需要成为 root 用户,或者必须使用 sudo 运行命令。

每次更改文件后/etc/ssh/sshd_config,需要重启ssh服务。命令是:

systemctl restart  sshd.service

任何您想要使用密码进行 ssh 登录的新用户,您需要将该用户添加到允许用户以空格作为每个用户的分隔符。

Eg:
AllowUsers root testUser

要使 root 用户能够通过 ssh 登录,您需要检查允许根用户登录,它的值应该是是的在文件中/etc/ssh/sshd_config

例如: 检查下面的 sshd_config 文件。通过此配置,您还可以使用 ssh 登录测试用户用户:

#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

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

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# 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 yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

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

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation sandbox
#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

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
AllowUsers root testUser

答案4

你测试adduser temipuser而不是useradd temipuser ???

sshd_conf 的 linux 手册说:

允许用户

    This keyword can be followed by a list of user name patterns, separated by 
spaces. If specified, login is allowed only for user names that match one of the 
patterns. Only user names are valid; a numerical user ID is not recognized. **By 
default, login is allowed for all users.** If the pattern takes the form USER@HOST 
then USER and HOST are separately checked, restricting logins to particular users 
from particular hosts. The allow/deny directives are processed in the following 
order: DenyUsers, AllowUsers, DenyGroups, and finally AllowGroups.

所以你不必添加AllowUsers,如果你添加这个选项,我不认为它会阻止远程root登录(如果你启用了)允许根用户登录

相关内容