Linux使用其他用戶(非root用戶)設(shè)置root權(quán)限及免密(Centos7為例)
Linux其他用戶設(shè)置root權(quán)限及免密
在linux系統(tǒng)中我們經(jīng)常要創(chuàng)建一些非root用戶來完成一些特定的操作,有時我們需要執(zhí)行一些root用戶才能執(zhí)行的命令,這時我們需要給該用戶設(shè)置root的權(quán)限
下面將演示如何操作:
1、首先創(chuàng)建一個test用戶
[root@smiletian ~]# groupadd -g 1234 tian [root@smiletian ~]# useradd -u 1234 -g tian test [root@smiletian ~]# passwd test Changing password for user test. New password: Retype new password: passwd: all authentication tokens updated successfully.
2、切換到test用戶下
當(dāng)我們執(zhí)行sudo命令時,會提示輸test用戶密碼,輸完后提示,test用戶不在sudoer文件里,所以是無法執(zhí)行sudo命令的。
[root@smiletian test]# su - test Last login: Sun Sep 18 23:35:57 PDT 2022 on pts/2 [test@smiletian ~]$ sudo mkdir abc [sudo] password for test: test is not in the sudoers file. This incident will be reported.
3、切換到root用戶
編輯 /etc/sudoers文件
[test@smiletian ~]$ su Password: [root@smiletian test]# vi /etc/sudoers
找到 ## Allow root to run any commands anywhere 這欄,在root下添加 test用戶,
## Allow root to run any commands anywhere root ALL=(ALL) ALL test ALL=(ALL) ALL
找到## Same thing without a password一欄,將%wheel ALL=(ALL)前面的#去掉,
- 更改前:
## Same thing without a password #%wheel ALL=(ALL) NOPASSWD: ALL
- 更改后:
## Same thing without a password %wheel ALL=(ALL) NOPASSWD: ALL
wq!保存退出。
4、切換到test用戶下
可以使用sudo命令,輸入一次密碼后,不再需要再每次都輸入密碼即可進行操作。
[root@smiletian test]# su - test Last login: Sun Sep 18 23:54:07 PDT 2022 on pts/2 [test@smiletian ~]$ su Password: [root@smiletian test]# vi /etc/sudoers [root@smiletian test]# su - test Last login: Mon Sep 19 00:08:24 PDT 2022 on pts/2 [test@smiletian ~]$ sudo mkdir abc [sudo] password for test: [test@smiletian ~]$ sudo mkdir abd [test@smiletian ~]$ sudo mkdir abf [test@smiletian ~]$ ll total 0 drwxr-xr-x. 2 root root 6 Sep 19 00:20 abc drwxr-xr-x. 2 root root 6 Sep 19 00:20 abd drwxr-xr-x. 2 root root 6 Sep 19 00:21 abf
Linux配置root權(quán)限,免密執(zhí)行sudo命令
配置用戶具有root權(quán)限,方便后期加sudo執(zhí)行root權(quán)限的命令
[root@master ~]# vim /etc/sudoers
修改/etc/sudoers文件,在%wheel這行下面添加一行
如下所示:
## Allow root to run any commands anywhere root ALL=(ALL) ALL ## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL 用戶名 ALL=(ALL) NOPASSWD:ALL
注意:
用戶名這一行不要直接放到root行下面,因為所有用戶都屬于wheel組,你先配置了用戶名具有免密功能,但是程序執(zhí)行到%wheel行時,該功能又被覆蓋回需要密碼。
所以用戶名要放到%wheel這行下面。
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
ubuntu下apache服務(wù)器操作方法小結(jié)
這篇文章主要介紹了ubuntu下apache服務(wù)器操作方法小結(jié),非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-12-12linux高性能測試之CPU模式批量由cpupower轉(zhuǎn)performance問題
這篇文章主要介紹了linux高性能測試之CPU模式批量由cpupower轉(zhuǎn)performance問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06Linux網(wǎng)絡(luò)設(shè)置之基礎(chǔ)操作命令詳解
大家好,本篇文章主要講的是Linux網(wǎng)絡(luò)設(shè)置之基礎(chǔ)操作命令詳解,感興趣的同學(xué)快來看一看吧,對你有用的話記得收藏起來,方便下次瀏覽2021-11-11linux VPS之間網(wǎng)站數(shù)據(jù)的備份與恢復(fù)(網(wǎng)站遷移教程)
有時候我們需要網(wǎng)站遷移或者網(wǎng)站數(shù)據(jù)需要備份或恢復(fù),那么就需要一些操作了,linux下操作都是命令下執(zhí)行的,特分享下,方便需要的朋友2014-02-02