sudo su 即使更改密碼後也不詢問密碼

sudo su 即使更改密碼後也不詢問密碼

我在 AWS 上有一個 ubuntu 實例。
獲得 ssh 登入後,我可以使用sudo su命令更改 root 密碼。
出於安全考慮,我想更改root密碼。所以我嘗試了以下方法:

root@email:/home/ubuntu# sudo passwd root
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
root@email:/home/ubuntu# 

當我嘗試更改密碼後sudo su,它不會要求輸入密碼

ubuntu@email:~$ sudo su
root@email:/home/ubuntu# 

然而,當我嘗試 only 時su,它會提示輸入一個:

ubuntu@email:~$ su
Password: 

如何實現安全或設定密碼sudo su

以下是 sudoers (visudo) 的詳細信息

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

答案1

sudoers文件中的這一行

#includedir /etc/sudoers.d

使其包含/etc/sudoers.d/目錄中的其他檔案。看起來該行已被註解掉,但事實並非如此;該指令#includedir以 . 開頭#。其中包含的文件之一可能設定了NOPASSWD導致問題的規則。

在進行更改之前,請確保您的普通用戶擁有有效的非空密碼。從這個答案:

sudo即使您沒有密碼,也會要求輸入密碼,並且不會接受空密碼。

如有疑問,請passwd為您的一般使用者呼叫並設定一個全新的密碼。

此命令應該告訴您需要檢查哪些文件:

sudo grep -r NOPASSWD /etc/sudoers.d/

您正在尋找的行可能如下所示:

ubuntu ALL=(ALL) NOPASSWD:ALL

註解掉( # ubuntu ALL=...)。比較這個答案

相關內容