您好,登錄后才能下訂單哦!
本篇內容主要講解“linux怎么給普通用戶提供root用戶的權限”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“linux怎么給普通用戶提供root用戶的權限”吧!
sudo 的特點
限制用戶執行指定的命令 記錄用戶執行的每一條命令 配置文件(/etc/sudoers)提供集中的用戶管理、權限與主機等參數 驗證密碼的后5分鐘內(默認值)無須再讓用戶再次驗證密碼
實戰演練
環境:Red Hat Enterprise Linux Server release 7.3
1. 測試普通用戶能否刪除 root 用戶創建的文件
[root@localhost ~]# mkdir /test [root@localhost ~]# cd /test [root@localhost test]# touch test.txt [root@localhost test]# mkdir test.dir [root@localhost test]# ll total 0 drwxr-xr-x. 2 root root 6 Jul 18 02:19 test.dir -rw-r--r--. 1 root root 0 Jul 18 02:19 test.txt [root@localhost test]# id test uid=1004(test) gid=1005(test) groups=1005(test) [root@localhost test]# su - test Last login: Thu Jul 18 02:17:11 EDT 2019 on pts/0 [test@localhost ~]$ cd /test [test@localhost test]$ ll total 0 drwxr-xr-x. 2 root root 6 Jul 18 02:19 test.dir -rw-r--r--. 1 root root 0 Jul 18 02:19 test.txt [test@localhost test]$ rm -rf test.dir/ rm: cannot remove ‘test.dir/’: Permission denied [test@localhost test]$ rm -rf test.txt rm: cannot remove ‘test.txt’: Permission denied [test@localhost test]$ ll total 0 drwxr-xr-x. 2 root root 6 Jul 18 02:19 test.dir -rw-r--r--. 1 root root 0 Jul 18 02:19 test.txt
2. 用 visudo 命令配置 sudo
[root@localhost ~]# visudo # 在 /etc/sudoers 配置文件中 root ALL=(ALL) ALL 這一行下面加入 test ALL=(ALL) ALL [root@localhost ~]# cat /etc/sudoers | grep ALL Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY" root ALL=(ALL) ALL test ALL=(ALL) ALL # %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS %wheel ALL=(ALL) ALL # %wheel ALL=(ALL) NOPASSWD: ALL %wheel ALL=(ALL) NOPASSWD: ALL # %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
3. 普通用戶結合 sudo 刪除 root 用戶的文件
[root@localhost ~]# echo "Jaking" | passwd --stdin test Changing password for user test. passwd: all authentication tokens updated successfully. [root@localhost ~]# su - test Last login: Thu Jul 18 02:34:50 EDT 2019 on pts/0 [test@localhost ~]$ cd /test/ [test@localhost test]$ ll total 0 drwxr-xr-x. 2 root root 6 Jul 18 02:19 test.dir -rw-r--r--. 1 root root 0 Jul 18 02:19 test.txt [test@localhost test]$ rm -rf test.dir/ rm: cannot remove ‘test.dir/’: Permission denied [test@localhost test]$ rm -rf test.txt rm: cannot remove ‘test.txt’: Permission denied [test@localhost test]$ sudo rm -rf test.dir/ [sudo] password for test: [test@localhost test]$ ll total 0 -rw-r--r--. 1 root root 0 Jul 18 02:19 test.txt [test@localhost test]$ sudo rm -rf test.txt [test@localhost test]$ ll total 0
4. sudo 免密配置
[test@localhost test]$ sudo cat /etc/shadow [sudo] password for test: root:$6$YZrm6scxO5zzICbR$fOzORb.0Ib9POZzJmrnzOGDqfFySp8X.9p5QpcpnJXWHIJvZcFpXQONyNigwrZbhXtyfnFn5F1mJsdkXS3jEF/::0:99999:7::: bin:*:16925:0:99999:7::: daemon:*:16925:0:99999:7::: adm:*:16925:0:99999:7::: ***省略部分輸出信息*** [test@localhost test]$ id test2 uid=1006(test2) gid=1007(test2) groups=1007(test2) [root@localhost ~]# visudo # 在 /etc/sudoers 配置文件中 %wheel ALL=(ALL) NOPASSWD: ALL 這一行的下面 加入test ALL=(ALL) NOPASSWD: ALL [root@localhost ~]# cat /etc/sudoers | grep NOPASSWD # %wheel ALL=(ALL) NOPASSWD: ALL %wheel ALL=(ALL) NOPASSWD: ALL test ALL=(ALL) NOPASSWD: ALL [test@localhost ~]$ sudo cat /etc/shadow # 用普通用戶查看 /etc/shadow 文件已經不需要再輸入當前登錄用戶的密碼 root:$6$YZrm6scxO5zzICbR$fOzORb.0Ib9POZzJmrnzOGDqfFySp8X.9p5QpcpnJXWHIJvZcFpXQONyNigwrZbhXtyfnFn5F1mJsdkXS3jEF/::0:99999:7::: bin:*:16925:0:99999:7::: daemon:*:16925:0:99999:7::: adm:*:16925:0:99999:7::: ***省略部分輸出信息***
5. 配置 sudo 的部分權限
[root@localhost ~]# cd /tmp [root@localhost tmp]# rm -rf * [root@localhost tmp]# ll total 0 [root@localhost tmp]# touch file [root@localhost tmp]# mkdir dir [root@localhost tmp]# ll total 0 drwxr-xr-x. 2 root root 6 Jul 18 03:01 dir -rw-r--r--. 1 root root 0 Jul 18 03:01 file [root@localhost tmp]# whereis cat cat: /usr/bin/cat /usr/share/man/man1/cat.1.gz [root@localhost tmp]# visudo # 把 /etc/sudoers 配置文件中的 test ALL=(ALL) ALL 改為 test ALL=(ALL) /usr/bin/cat [root@localhost ~]# cat /etc/sudoers | grep cat ## Updating the locate database # Defaults specification # Preserving HOME has security implications since many programs test ALL=(ALL) /usr/bin/cat [root@localhost ~]# su - test Last login: Thu Jul 18 03:06:55 EDT 2019 on pts/0 [test@localhost ~]$ sudo cat /etc/shadow # 給 test 用戶配置了查看權限 root:$6$YZrm6scxO5zzICbR$fOzORb.0Ib9POZzJmrnzOGDqfFySp8X.9p5QpcpnJXWHIJvZcFpXQONyNigwrZbhXtyfnFn5F1mJsdkXS3jEF/::0:99999:7::: bin:*:16925:0:99999:7::: daemon:*:16925:0:99999:7::: adm:*:16925:0:99999:7::: ***省略部分輸出信息*** [test@localhost ~]$ cd /tmp [test@localhost tmp]$ ll total 0 drwxr-xr-x. 2 root root 6 Jul 18 03:06 dir -rw-r--r--. 1 root root 0 Jul 18 03:01 file [test@localhost tmp]$ rm -rf dir # test 用戶已經沒有了刪除權限 rm: cannot remove ‘dir’: Permission denied [test@localhost tmp]$ rm -rf file # test 用戶已經沒有了刪除權限 rm: cannot remove ‘file’: Permission denied [test@localhost tmp]$ ll total 0 drwxr-xr-x. 2 root root 6 Jul 18 03:06 dir -rw-r--r--. 1 root root 0 Jul 18 03:01 file
到此,相信大家對“linux怎么給普通用戶提供root用戶的權限”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。