每个 root 命令通过 ssh 都会失败并出现“未找到命令”,但在 VNC 控制台中可以运行吗?

每个 root 命令通过 ssh 都会失败并出现“未找到命令”,但在 VNC 控制台中可以运行吗?

我有一个通过 SSH 访问的 VPS。更新到 Debian 10 后,通过 ssh 以 root 身份登录时,我无法再运行 root 命令(我已经重新启动)。使用主机的 VNC 连接控制台进行访问时,一切正常。

作为示例,iptables但这对所有命令都有效。

marius:/home/afh whoami                                                                         
root                 
marius:/home/afh iptables                                                                       
zsh: command not found: iptables
marius:/home/afh apt-get install iptables                                                       
Reading package lists... Done
Building dependency tree       
Reading state information... Done
iptables is already the newest version (1.8.2-4).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

我已尝试按照建议重新安装关于这个答案

marius:/home/afh apt-get --reinstall install iptables                                           
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 399 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://cdn-fastly.deb.debian.org/debian buster/main amd64 iptables amd64 1.8.2-4 [399 kB]
Fetched 399 kB in 0s (1,162 kB/s)
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76, <> line 1.)
debconf: falling back to frontend: Readline
(Reading database ... 327810 files and directories currently installed.)
Preparing to unpack .../iptables_1.8.2-4_amd64.deb ...
Unpacking iptables (1.8.2-4) over (1.8.2-4) ...
Setting up iptables (1.8.2-4) ...
Processing triggers for man-db (2.8.5-2) ...
localepurge: Disk space freed in /usr/share/locale: 0 KiB
localepurge: Disk space freed in /usr/share/man: 0 KiB

Total disk space freed by localepurge: 0 KiB

marius:/home/afh iptables -L                                                                    
zsh: command not found: iptables
marius:/home/afh whoami                                                                         
root

PATH 看起来不错,根据这个答案这个答案

marius:/home/afh echo $PATH                                                                      
/root/.bin:/home/afh/.bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

bash 也失败了:

root@marius:/home/afh# iptables -L
bash: iptables: command not found

答案1

你还没告诉我们你是怎样变成的root

如果你正在使用普通版本su,那么升级到 Buster 会破坏它 — — 实际上它修复了它,因为它已经损坏了 ;-)

这个想法是,su现在不再使用PATH来自目标用户环境(root在您的情况下)和PATH普通用户的环境不包含/sbin/usr/sbin目录,这就是为什么/usr/sbin/iptables无法使用其未修饰的(短)名称进行访问。

快速解决方法是使用su -强制该程序切换到“登录”模式。

了解更多信息。

相关内容