嗯,这不是一个好主意,但它是可能的。正如这里有人指出的那样,您无法阻止 root 成为计算机的神,但您可以修改“su”程序以询问密码。它可以防止 root 重新登录到其他帐户,除非他编译自己的 su 版本并使用它。
首先,您需要一个编译器才能重新构建 su。以 root 身份执行:
apt-get install build-essential
Run Code Online (Sandbox Code Playgroud)
然后,下载并准备GNU Coreutils:
ftp://ftp.task.gda.pl/pub/gnu/coreutils/coreutils-8.13.tar.gz
tar xvf coreutils-8.20.tar.xz
cd coreutils-8.20
./configure
Run Code Online (Sandbox Code Playgroud)
现在访问src目录并找到su.c文件。在第 223 行,您会发现:
if (getuid () == 0 || !correct || correct[0] == '\0')
Run Code Online (Sandbox Code Playgroud)
将其更改为:
if (!correct || correct[0] == '\0')
Run Code Online (Sandbox Code Playgroud)
现在,回到coreutils-8.20目录,运行 make。编译可能需要很长时间。完成后,用新的 su 覆盖当前的 su 二进制文件:
cp src/su `which su`
Run Code Online (Sandbox Code Playgroud)
再说一遍——你做错了。