linux怎么给普通用户提供root用户的权限
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,本篇内容主要讲解"linux怎么给普通用户提供root用户的权限",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"linux怎么给普通用户提供root用户的权
千家信息网最后更新 2025年12月02日linux怎么给普通用户提供root用户的权限
本篇内容主要讲解"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]# lltotal 0drwxr-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 testuid=1004(test) gid=1005(test) groups=1005(test)[root@localhost test]# su - testLast login: Thu Jul 18 02:17:11 EDT 2019 on pts/0[test@localhost ~]$ cd /test[test@localhost test]$ lltotal 0drwxr-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]$ lltotal 0drwxr-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 ALLDefaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"root ALL=(ALL) ALLtest 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 testChanging password for user test.passwd: all authentication tokens updated successfully.[root@localhost ~]# su - testLast login: Thu Jul 18 02:34:50 EDT 2019 on pts/0[test@localhost ~]$ cd /test/[test@localhost test]$ lltotal 0drwxr-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]$ lltotal 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]$ lltotal 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 test2uid=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: ALLtest 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]# lltotal 0[root@localhost tmp]# touch file[root@localhost tmp]# mkdir dir[root@localhost tmp]# lltotal 0drwxr-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 catcat: /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 programstest ALL=(ALL) /usr/bin/cat[root@localhost ~]# su - testLast 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]$ lltotal 0drwxr-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]$ lltotal 0drwxr-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用户的权限"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
用户
权限
配置
文件
普通
部分
信息
命令
密码
输出
一行
内容
学习
验证
实用
更深
主机
兴趣
再次
参数
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
服务器安全防护哪家好服务
智软软件开发有限公司
信息管理与网络技术有关系吗
2020世界网络安全大会时间
中国传媒大学调剂到网络安全专业
网络安全顾问
企业如何进入当地企业数据库
网络安全规定11条
杀掉数据库用户进程
两台服务器怎么使用一个公网ip
网络安全信息方面进行的合作
天津中新互联网科技
市监局网络安全事件应急预案
建设网站服务器空间
城管局网络安全工作总结
赌博马甲软件开发
曙光服务器raid手册
三丰云虚拟服务器怎么样
域名换服务器以后要备案吗
实现数据库安全机制的技术
青少年如何看待网络技术
院前创伤急救中心软件开发商
联科网络安全准入助手能监控吗
大连服务器租用
科技和互联网公司简介
刀塔2电信服务器列表
网络安全宣传活动宣传语
openssl 服务器
如何选择适合自己的软件开发
清华网络安全专业课表