Linux中國

如何在 Linux 中不輸入密碼運行 sudo 命令

此設置在 /etc/sudoers 文件中完成,這是使用 sudo 命令的默認安全策略;在用戶許可權指定部分。

重要:在 sudeors 文件中,默認打開的 authenticate 參數用於驗證目的。如果設置了它,用戶必須通過密碼(或其他身份驗證方法)進行身份驗證,然後才能使用 sudo 運行命令。

但是,可以使用 NOPASSWD(當用戶調用 sudo 命令時不需要密碼)標記來覆蓋此默認值。

配置用戶許可權的語法如下:

user_list host_list=effective_user_list tag_list command_list

其中:

  1. user_list - 用戶列表或已經設置的用戶別名。
  2. host_list - 主機列表或用戶可以在其上運行 sudo 的主機別名。
  3. effective_user_list - 以該用戶或別名運行的用戶列表
  4. tag_list - 標籤列表,如 NOPASSWD
  5. command_list - 用戶使用 sudo 運行的命令或命令別名列表。

要允許用戶(下面的示例中的 aaronkilik)使用 sudo 不輸入密碼即可運行所有命令,請打開 sudoers 文件:

$ sudo visudo

添加下面的行:

aaronkilik ALL=(ALL) NOPASSWD: ALL

對於組而言,在組名前面使用 % 字元;這意味著 sys 組的所有成員都可以不用密碼使用 sudo

%sys ALL=(ALL) NOPASSWD: ALL

要允許用戶不用密碼使用 sudo 運行指定命令(/bin/kill),添加下面的行:

aaronkilik ALL=(ALL) NOPASSWD: /bin/kill

下面的行會讓 sys 組成員在使用 sudo 運行命令:/bin/kill/bin/rm 時不用輸入密碼:

%sys ALL=(ALL) NOPASSWD: /bin/kill, /bin/rm

Run sudo Without Password

不用密碼運行 sudo

對於更多的 sudo 配置和其他使用選項,請閱讀我們有更多例子描述的文章,:

在本篇中,我們討論了如何配置 sudo 命令來不用輸入密碼運行。不要忘記在評論欄中給我們提供你關於這份指導的想法和其他對於 Linux 系統管理員有用的 sudoers 配置。

作者簡介:

Aaron Kili 是 Linux 和 F.O.S.S 愛好者,將來的 Linux SysAdmin 及 web 開發者,目前是 TecMint 的內容創作者,他喜歡用電腦工作,並堅信分享知識。

via: http://www.tecmint.com/run-sudo-command-without-password-linux/

作者:Aaron Kili 譯者:geekpi 校對:jasminepeng

本文由 LCTT 原創編譯,Linux中國 榮譽推出


本文轉載來自 Linux 中國: https://github.com/Linux-CN/archive

對這篇文章感覺如何?

太棒了
0
不錯
0
愛死了
0
不太好
0
感覺很糟
0
雨落清風。心向陽

    You may also like

    5 Comments

    1. 350fairfax nordvpn promo code
      Howdy I am so thrilled I found your webpage, I really found you
      by accident, while I was researching on Askjeeve for something else, Regardless I am
      here now and would just like to say thank you for a marvelous post and a all round entertaining blog (I also love the theme/design), I don』t have time to browse it all at the minute but I have book-marked it and also included your RSS feeds,
      so when I have time I will be back to read more,
      Please do keep up the excellent b.

    2. Pretty nice post. I just stumbled upon your weblog and wanted to say that
      I’ve really enjoyed surfing around your blog
      posts. In any case I will be subscribing to your rss feed
      and I hope you write again soon!

      my webpage :: nordvpn coupons inspiresensation

    3. With havin so much content do you ever run into any problems of plagorism or copyright violation?
      My blog has a lot of exclusive content I’ve either authored myself or outsourced but it
      looks like a lot of it is popping it up all over the web without my agreement.
      Do you know any methods to help protect against content from being stolen? I’d definitely appreciate it.

      Review my blog post; nordvpn coupons inspiresensation

    4. This design is spectacular! You obviously know how to
      keep a reader amused. Between your wit and your videos, I was
      almost moved to start my own blog (well, almost…HaHa!) Great job.
      I really enjoyed what you had to say, and more
      than that, how you presented it. Too cool!

      Here is my website :: nordvpn coupons Inspiresensation

    5. Great post. I was checking constantly this weblog and I am impressed!

      Very helpful info particularly the closing phase 🙂 I deal with such information much.
      I used to be seeking this certain information for a very long time.
      Thanks and best of luck.

      Also visit my web site; nordvpn coupons inspiresensation

    Leave a reply

    您的郵箱地址不會被公開。 必填項已用 * 標註

    這個站點使用 Akismet 來減少垃圾評論。了解你的評論數據如何被處理

    More in:Linux中國