ไม่มีพรอมต์รหัสผ่านที่คำสั่ง sudo


13

เมื่อใดก็ตามที่ฉันออกคำสั่ง sudo apt-get install **มันจะไม่ถามรหัสผ่าน

จะทำให้มันถามรหัสผ่านได้อย่างไร

sudoer ของฉัน:

ubuntu:~$ sudo cat /etc/sudoers
#
# 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    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/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
ALL ALL=(ALL) NOPASSWD:ALL

2
แสดงความคิดเห็นในบรรทัดสุดท้าย [#ALL ALL = (ALL) NOPASSSD: ALL]
shantanu

คำตอบ:


18

แก้ไข/etc/sudoersโดยใช้sudo visudoและลบบรรทัดสุดท้าย:

ALL ALL=(ALL) NOPASSWD:ALL

(โดยวิธีการโปรดทราบว่าบรรทัดนี้ในตอนท้ายของไฟล์ไม่ได้เป็นวิธีที่ต้องการเพื่อsudo ไม่ให้แจ้งรหัสผ่านสำหรับผู้ที่ต้องการทำเช่นนั้น)


1
ขอบคุณสำหรับคำตอบของ Eliah แต่โดยค่าเริ่มต้นแล้วมันจะเป็นยังไง?
data9

1
มันไม่ควรจะมีโดยค่าเริ่มต้น มักจะไม่ปรากฏใน/etc/sudoersไฟล์ใน Ubuntu ไม่ว่าในกรณีใดการแสดงความคิดเห็นออกมา (โดยใส่ไว้#ด้านหน้า) ก็ดีพอ ๆ กับการลบบรรทัดและทำให้ง่ายต่อการเรียกคืนหากคุณต้องการกลับมา
Eliah Kagan

2
ตกลงดังนั้นวิธีที่ดีที่สุดที่จะทำให้ sudo ไม่ได้รับพร้อมท์สำหรับรหัสผ่านคืออะไร?
michaelbn

@EliahKagan ขอบคุณเพื่อนของฉันฉันมีปัญหาเดียวกันและสิ่งนี้ได้รับการแก้ไข .... แต่ฉันมีข้อสงสัยนี้ฉันไม่เคยแก้ไขไฟล์เหล่านี้วิธีการที่สามารถแก้ไขได้โดยไม่ได้รับอนุญาตจากผู้ใช้คืออะไร?
Severus Tux

@SeverusTux คุณจะได้รับอนุญาตให้รูทโปรแกรมจากแหล่งที่ไม่น่าเชื่อถือ ซึ่งแก้ไขไฟล์นี้เพื่อที่ในอนาคตจะไม่ต้องถามรหัสผ่านจากคุณซ้ำแล้วซ้ำอีก ... ............ คุณสามารถคิดเกี่ยวกับไวรัส .. หรือม้าโทรจัน ...
sanjeev

4

ใช้คำสั่งนี้เพื่อค้นหาสาเหตุของปัญหา:

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

ในกรณีของฉัน:

/etc/sudoers.d/50_stack_sh:1:username ALL=(root) NOPASSWD:ALL

แสดงความคิดเห็นบรรทัดด้วย # และปิดสถานีของคุณ


0

ฉันคิดว่าเป็นการดีกว่าที่จะเพิ่ม "ผู้ใช้ผู้ดูแลระบบ" ที่ส่วนท้ายของไฟล์เนื่องจากผู้ดูแลระบบไม่ควรใส่รหัสผ่านในทุกการสั่งซื้อในเทอร์มินัลและไม่อนุญาตให้ผู้ใช้รายอื่นทำ:

# 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    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/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
# ALL ALL=(ALL) NOPASSWD:ALL
(user here) ALL=(ALL) NOPASSWD:ALL

ใช้การจัดรูปแบบ ไฮไลต์ข้อความและใช้ปุ่ม <$>
Panther
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.