允許用戶無需密碼即可使用 sudo

允許用戶無需密碼即可使用 sudo

在沙箱虛擬機器環境中,我設定了 Ubuntu Linux,它受防火牆保護,無法從本機系統外部存取。因此,在該虛擬機器上,我想為管理使用者(我設定的)提供使用 sudo 運行任何內容而不需要密碼的能力。

雖然我知道這並不安全,但該虛擬機器並非始終處於開啟狀態,並且需要我的個人密碼才能運作。因此,即使這不“安全”,有沒有辦法獲得所需的功能?

答案1

曼蘇多爾斯

   NOPASSWD and PASSWD

   By default, sudo requires that a user authenticate him or herself
   before running a command.  This behavior can be modified via the
   NOPASSWD tag.  Like a Runas_Spec, the NOPASSWD tag sets a default for
   the commands that follow it in the Cmnd_Spec_List.  Conversely, the
   PASSWD tag can be used to reverse things.  For example:

    ray  rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm

   would allow the user ray to run /bin/kill, /bin/ls, and /usr/bin/lprm
   as root on the machine rushmore without authenticating himself.

另一種標籤是ALL,允許使用者 ray 在任何主機上執行任何命令而無需密碼,您可以使用:

ray ALL= NOPASSWD: ALL

答案2

正如您所提到的,除非系統在特定的安全環境中運行,否則禁用密碼提示是一個壞主意。

一種可能的解決方案是這一行,我發現它比 NOPASSWD 選項更容易記住。取得管理權限並運行

$ visudo

並添加以下行

預設值: 使用者名稱

這將完全停用特定用戶的密碼提示。

相關內容