我没有编辑我的 sudoers,但在命令行中运行时我不必输入密码sudo
。我可以通过打开终端来运行任何 sudo 命令而无需输入密码,即使在重新启动系统后也是如此,我该如何停止这种情况?
uid=1000(ktcool) gid=1000(ktcool) groups=1000(ktcool),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),124(sambashare)
答案1
使用visudo
编辑您的 sudoers 文件并查找NOPASSWD:
- 这是禁用用户密码提示的指令(您永远不必输入目标用户的密码,即 root 密码)。只需删除该指令(包括末尾的冒号)即可要求您重新输入密码以使用 sudo(除非您最近使用过它,那么它仍然被缓存,您可以使用 清除它sudo -k
)
答案2
在/etc/sudoers
文件中,admin 组应如下所示,%admin ALL=(ALL) ALL
而 root 则为ALL=(ALL:ALL) ALL
。由于命令的输出id
显示您属于多个组(如 lpadmin),请检查其中是否有与 root 相同的行。将它们更改为与 admin 相同,保存,重新启动,然后让我们知道一切是否恢复正常。
答案3
尝试sudo --list
向我们展示您帐户的活动 sudo 配置:
skath@beast:~$ sudo --list
Matching Defaults entries for skath on beast:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User skath may run the following commands on beast:
(ALL : ALL) ALL
skath@beast:~$
检查缓存凭据上的时间戳,这可以帮助您了解为什么没有提示您:
skath@beast:~$ sudo ls -al /var/lib/sudo/$USER/
total 20
drwx------ 2 root skath 4096 Jan 28 14:27 .
drwx------ 3 root root 4096 Jan 28 13:52 ..
-rw------- 1 root skath 40 Feb 5 16:18 1
-rw------- 1 root skath 40 Jan 28 14:51 2
-rw------- 1 root skath 40 Jan 28 13:56 tty1
skath@beast:~$
用来sudo --remove-timestamp
尝试清除所有缓存的凭据。
从man sudo
:
-K, --remove-timestamp
Similar to the -k option, except that it removes the
user's cached credentials entirely and may not be used
in conjunction with a command or other option. This
option does not require a password. Not all security
policies support credential caching.
-k, --reset-timestamp
When used without a command, invalidates the user's
cached credentials. In other words, the next time sudo
is run a password will be required. This option does
not require a password and was added to allow a user to
revoke sudo permissions from a .logout file.
When used in conjunction with a command or an option
that may require a password, this option will cause sudo
to ignore the user's cached credentials. As a result,
sudo will prompt for a password (if one is required by
the security policy) and will not update the user's
cached credentials.
Not all security policies support credential caching.
答案4
sudo -i
如果您不想在修改系统(或其他系统)时不时输入密码,并且不想修改任何系统文件,那么这就是您的最佳选择。 当您关闭控制台或输入密码时,它将切换为root
您使用用户密码,您将恢复为普通用户。希望这能奏效,谢谢:)sudo
exit