歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下sudo的使用

Linux下sudo的使用

日期:2017/2/27 16:06:12   编辑:Linux教程
Linux下Sudo命令的使用方法 “Sudo” 是Unix/Linux平台上的一個非常有用的工具,它允許系統管理員分配給普通用戶一些合理的“權利”,讓他們執行一些只有超級用戶或其他特許用戶才能 完成的任務,比如:運行一些像mount,halt,su之類的命令,或者編輯一些系統配置文件,
· 如果一個用戶沒有列在 /etc/sudoers 中嘗試使用 sudo
將會通告給管理員 ## Allow root to run any commands anywhere
root ALL=(ALL) ALL 用戶或用戶別名 主機或主機別名 操作者 命令或命令別名 vim /etc/sudoers
User_Alias USERS = lj, kitty
Cmnd_Alias NETWORKS = /sbin/service, /sbin/chkconfig
root    ALL=(ALL)       ALL
oracle  ALL=(ALL) NOPASSWD:NETWORKS
USERS   ALL=(ALL)  NETWORKS

測試:
[root@station31 ~]# su - oracle
[oracle@station31 ~]$ /sbin/service httpd restart
rm: cannot remove `/var/run/httpd.pid': Permission denied
Starting httpd:
touch: cannot touch `/var/lock/subsys/httpd': Permission denied
[oracle@station31 ~]$ sudo /sbin/service httpd restart
Stopping httpd: [  OK  ]
Starting httpd: [  OK  ]

[kitty@station31 ~]$ /sbin/service httpd restart
rm: cannot remove `/var/run/httpd.pid': Permission denied
Starting httpd:
touch: cannot touch `/var/lock/subsys/httpd': Permission denied
[kitty@station31 ~]$ sudo /sbin/service httpd restart
Password:
Stopping httpd: [  OK  ]
Starting httpd: [  OK  ]
總結: 取消原root權限即注釋root ALL=(ALL) ALL; 可以自己創建一個用戶,利用sudo工具使其用戶具有“root”權限,並設置PATH,大大提高系統安全性。
Copyright © Linux教程網 All Rights Reserved