linux 操作系统下 root 无法登录,用户无法切换故障处理
一:ssh 无法直接root登录
root@meng:~# ssh root@192.168.10.16
root@192.168.10.16's password:
Permission denied, please try again.
root@192.168.10.16's password:
二:普通用户登录后无法切换到root
root@meng:~# ssh meng@192.168.10.16
meng@192.168.10.16's password:
Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-72-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Thu Aug 29 09:54:56 AM CST 2024
System load: 0.166015625
Usage of /: 61.0% of 32.37GB
Memory usage: 40%
Swap usage: 0%
Processes: 286
Users logged in: 2
IPv4 address for br-82ee9ae1da4f: 172.18.0.1
IPv4 address for br-b8b5b2af3a6d: 172.19.0.1
IPv4 address for br-cdec9eb525ca: 172.20.0.1
IPv4 address for docker0: 172.17.0.1
IPv4 address for ens33: 192.168.10.16
IPv4 address for tun0: 10.10.0.1
* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
just raised the bar for easy, resilient and secure K8s cluster deployment.
https://ubuntu.com/engage/secure-kubernetes-at-the-edge
* Introducing Expanded Security Maintenance for Applications.
Receive updates to over 25,000 software packages with your
Ubuntu Pro subscription. Free for personal use.
https://ubuntu.com/pro
Expanded Security Maintenance for Applications is not enabled.
205 updates can be applied immediately.
112 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Last login: Thu Aug 29 09:37:10 2024 from 192.168.10.20
meng@meng:~$ sudo su -
[sudo] password for meng:
su: failed to execute meng: No such file or directory
meng@meng:~$ su -
Password:
su: Authentication failure
meng@meng:~$
目标机器上的ssh配置:
root@meng:/opt# grep Root /etc/ssh/sshd_config
#PermitRootLogin prohibit-password
PermitRootLogin yes
# the setting of "PermitRootLogin without-password".
root@meng:/opt# grep Password /etc/ssh/sshd_config
PasswordAuthentication yes
#PermitEmptyPasswords no
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication, then enable this but set PasswordAuthentication
root@meng:/opt#
重置root密码,并重启sshd
root@meng:/opt# passwd root
New password:
Retype new password:
passwd: password updated successfully
root@meng:/opt# systemctl restart sshd
root@meng:/opt# systemctl status sshd
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2024-08-29 09:57:25 CST; 4s ago
Docs: man:sshd(8)
man:sshd_config(5)
Process: 37073 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 37074 (sshd)
Tasks: 1 (limit: 9361)
Memory: 1.7M
CPU: 14ms
CGroup: /system.slice/ssh.service
└─37074 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
Aug 29 09:57:25 meng systemd[1]: Starting OpenBSD Secure Shell server...
Aug 29 09:57:25 meng sshd[37074]: Server listening on 0.0.0.0 port 22.
Aug 29 09:57:25 meng sshd[37074]: Server listening on :: port 22.
Aug 29 09:57:25 meng systemd[1]: Started OpenBSD Secure Shell server.
/var/log/syslog 及 /var/log/auth.log 日志
原因:
Failed password for invalid user root from 192.168.10.20 port 52796 ssh2
User root not allowed because shell meng does not exist
用户meng shell 不存在
查看用户是否正常
root@meng:/opt# cat /etc/passwd |grep meng
root:x:0:0:root:/root:meng
meng:x:1000:1000:mengsy,120,120,120,120:/home/meng:/bin/bash
root@meng:/opt# cat /etc/passwd |grep root
root:x:0:0:root:/root:meng
修复:
恢复正常