CentOS7給普通用戶執行root相關權限

給普通用戶執行root用戶權限的功能(重啓mysql服務) ---------------------------------------------------- 方法一(不推薦): 以root用戶身份登陸(或su進去) 修改/etc/sudoers文件(不要直接修改文件,不然權限有問題),直接使用命令 # visudo 找到 root    ALL=(ALL)       ALL 這行,在之下加入一行 lifw    ALL=/usr/bin/systemctl restart mysql.service 保存退出 :wq 切換會普通用戶(從新登陸或exit) 查看有哪些權限 $sudo -l 普通用戶執行 sudo /usr/bin/systemctl restart mysql.service 輸入本賬號(普通用戶)的密碼便可。 若是給普通用戶執行所有root權限時,只須要複製一份 root    ALL=(ALL)       ALL 並將root改爲普通用戶的名字便可。 須要從新登陸。 ------------------------------------------------------ 方法二(推薦): 由於軟件升級, /etc/sudoers 可能會被覆蓋掉,因此好的習慣是在 /etc/sudoers.d 中添加 在 /etc/sudoers.d 目錄中增長一個文件,添加相同的內容 # vim test 添加以下代碼: tom ALL=(ALL) ALL 保存退出,用這個賬號登陸,sudo後具備root權限 另:其餘配置方式與在sudoers文件中的同樣。 注意(若是發現沒有成功,看是否知足下面2個條件): 1. 新建的這個文件不能以 「~」結尾,或者文件名中不能包含 "." (The file in /etc/sudoers do not end in '~' or contain a '.' character) 2. 新建的文件的用戶和組都必須是root,而且文件的權限是440.(Note that there must be at least one file in the sudoers.d directory (this one will do), and all files in this directory should be mode 0440.)
相關文章
相關標籤/搜索