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用戶下
當我們執(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)文章
Ubuntu16.04 靜態(tài)IP地址設(shè)置(NAT方式)
這篇文章主要介紹了Ubuntu16.04 靜態(tài)IP地址設(shè)置(NAT方式),詳細的介紹了為VMware虛擬機內(nèi)安裝的Ubuntu 16.04設(shè)置靜態(tài)IP地址NAT方式,有興趣的可以了解一下。2017-02-02
Linux在應(yīng)用層讀寫寄存器的方法及實現(xiàn)實例
這篇文章主要介紹了Linux在應(yīng)用層讀寫寄存器的方法及實現(xiàn)實例的相關(guān)資料,需要的朋友可以參考下2017-02-02
Linux內(nèi)存泄露的原因排查和解決方案(內(nèi)存管理方法)
文章主要介紹了運維團隊在Linux處理LB服務(wù)內(nèi)存暴漲、內(nèi)存報警問題的過程,從發(fā)現(xiàn)問題、排查原因到制定解決方案,并從中學(xué)習(xí)了Linux內(nèi)存管理的相關(guān)知識2025-02-02
CentOS 7.x NAT模式上網(wǎng)配置步驟詳解
本篇文章主要介紹了CentOS 7.x NAT模式上網(wǎng)配置步驟詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02
淺析CentOS8虛擬機訪問Windows10主機文件夾方法
這篇文章主要介紹了CentOS8虛擬機訪問Windows10主機文件夾方法,本文圖文并茂給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-10-10

