" />

亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Linux使用其他用戶(非root用戶)設(shè)置root權(quán)限及免密(Centos7為例)

 更新時(shí)間:2024年05月23日 09:31:15   作者:宇宙超級(jí)無敵天下第一爆龍戰(zhàn)士  
這篇文章主要介紹了Linux使用其他用戶(非root用戶)設(shè)置root權(quán)限及免密(Centos7為例),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Linux其他用戶設(shè)置root權(quán)限及免密

在linux系統(tǒng)中我們經(jīng)常要?jiǎng)?chuàng)建一些非root用戶來完成一些特定的操作,有時(shí)我們需要執(zhí)行一些root用戶才能執(zhí)行的命令,這時(shí)我們需要給該用戶設(shè)置root的權(quán)限

下面將演示如何操作:

1、首先創(chuàng)建一個(gè)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命令時(shí),會(huì)提示輸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命令,輸入一次密碼后,不再需要再每次都輸入密碼即可進(jìn)行操作。

[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行下面,因?yàn)樗杏脩舳紝儆趙heel組,你先配置了用戶名具有免密功能,但是程序執(zhí)行到%wheel行時(shí),該功能又被覆蓋回需要密碼。

所以用戶名要放到%wheel這行下面。

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論