如何在Linux環(huán)境為用戶添加sudo權(quán)限
sudo的配置文件
sudo默認(rèn)配置文件是**/etc/sudoers** ,一般使用Linux指定編輯工具visudo ,此工具的好處是可以進(jìn)行錯(cuò)誤檢查。在添加規(guī)則不符合語法規(guī)則時(shí),保存退出時(shí)會提示給我們錯(cuò)誤信息;配置好后,可以用切換到您授權(quán)的普通用戶下,通過sudo -l來查看哪些命令是可以執(zhí)行的或禁止的;
/etc/sudoers 文件中每行是一個(gè)規(guī)則,前面帶有#號可以當(dāng)作是注釋的內(nèi)容,并不執(zhí)行;如果規(guī)則很長,可以寫在多列上,可以用\號來續(xù)行。
/etc/sudoers 的規(guī)則可分為兩類;一類是授權(quán)規(guī)則,另一類是別名定義;別名定義并不是必須的,但授權(quán)規(guī)則是必須的;
進(jìn)入root用戶,打開sudoers文件
# # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d
實(shí)例1:普通用戶lin添加sudo權(quán)限,在“root ALL=(ALL)ALL”這一行下面,加入如下圖所示的一行(用戶名 ALL=(ALL) ALL),并保存。
lin ALL=(ALL:ALL) ALL
實(shí)例2:如何想讓普通用戶lin具有/etc/init.d/nagios腳本重啟的權(quán)限
lin ALL=NOPASSWD:/etc/init.d/nagios restart
實(shí)例3:讓普通用戶lin具有所有超級用戶的權(quán)限而又不用輸入密碼
lin ALL=(ALL)NOPASSWD:ALL
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持本站。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。