標籤: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