linux的權力分配-sudo

來源:互聯網
上載者:User

標籤:style   c   com   a   檔案   使用   

         Sudo是Unix/Linux平台上的一個非常有用的工具,它允許系統管理員分配給普通使用者一些合理的“權力”,讓他們執行一些只有超級使用者或其他特許使用者才能完成的任務(主要體現為命令),比如:運行一些像mount,halt,su,useradd、userdel之類的命令,或者編輯一些系統設定檔,像/etc/mtab, /etc/samba/smb.conf等。這樣以來,就不僅減少了root使用者的登陸次數和行政時間,也提高了系統安全性。


在沒有給一個普通使用者賦予某項權利時,即使使用在使用命令之前加sudo命令,仍然不行。

[[email protected] ~]$ useradd xx
-bash: /usr/sbin/useradd: 許可權不夠
[[email protected] ~]$ sudo useradd xx
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.
[sudo] password for book: 
book is not in the sudoers file.  This incident will be reported.

[[email protected] book]# vim /etc/sudoers

權利分配的方法:

權力分配主要通過在設定檔/etc/sudoers按照約定格式添加一行資訊。(配置該檔案是要以root身份配置)
使用者名稱主機名稱=(運行使用者名稱) 可啟動並執行命令   

例1. book ALL=(ALL) /usr/sbin/useradd                                       //假設系統裡有book這個使用者,對其賦予useradd權利
例2. book ALL=(ALL) NOPASSWD: /usr/sbin/useradd                //不要求輸入密碼認證

則切換到book使用者下後,執行sudo useradd   xx        //普通使用者book就可以增加一個使用者xx


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.