Linux中配置sudo用户访问权限

这篇具有很好参考价值的文章主要介绍了Linux中配置sudo用户访问权限。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、如何在 Linux 中配置 sudo 的访问权限
1.1、添加一个Linux普通用户有 sudo 权限
[root@localhost ~]# useradd test  // 创建一个普通用户为:test
[root@localhost ~]# 
[root@localhost ~]# passwd test  // 设置用户test密码为:test
Changing password for user test.
New password: # test
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:   # test
passwd: all authentication tokens updated successfully.  # 看到successfully 表示设置成功
[root@localhost ~]# 
[root@localhost ~]# id test
uid=1000(test) gid=1000(test) groups=1000(test)
[root@localhost ~]# 
[root@localhost ~]# vim /etc/sudoers
...省略N
root    ALL=(ALL)       ALL
test    ALL=(ALL)       NOPASSWD: ALL  // 添加这一行
...省略N

linux sudoers 用户权限配置,linux,linux,运维,服务器


1.2、测试普通用户的 sudo 权限
[root@localhost ~]# su - test  // 登录用户 test
Last login: Wed Jun 28 16:35:53 CST 2023 from 192.168.192.1 on pts/1
[test@localhost ~]$ 
[test@localhost ~]$ cd /opt/
[test@localhost opt]$ 
[test@localhost opt]$ ll
total 0
-rw-r--r-- 1 root root 0 Jun 28 16:38 school  // 文件school 所有者和所属组为:root
[test@localhost opt]$ 
[test@localhost opt]$ cp school test.txt  // 使用用户test 复制school 文件为 test.txt 
cp: cannot create regular file ‘test.txt’: Permission denied  # 提示权限不够
[test@localhost opt]$ 
[test@localhost opt]$ ll
total 0
-rw-r--r-- 1 root root 0 Jun 28 16:38 school
[test@localhost opt]$ 
[test@localhost opt]$ sudo cp school test.txt  // 需要加上 sudo 
[test@localhost opt]$ 
[test@localhost opt]$ ll
total 0
-rw-r--r-- 1 root root 0 Jun 28 16:38 school
-rw-r--r-- 1 root root 0 Jun 28 17:13 test.txt  # 复制成功
[test@localhost opt]$ 

1.3、添加多个Linux普通用户有 sudo 权限
# 创建多个普通用户
[root@localhost ~]# useradd user1  // 创建用户:user1
[root@localhost ~]# 
[root@localhost ~]# passwd user1  // 设置密码为:user1
Changing password for user user1.
New password: 
BAD PASSWORD: The password is shorter than 7 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost ~]# 
[root@localhost ~]# id user1
uid=1001(user1) gid=1001(user1) groups=1001(user1)
[root@localhost ~]# 

[root@localhost ~]# useradd user2   // 创建用户:user2
[root@localhost ~]# 
[root@localhost ~]# passwd user2   // 设置密码为:user2
Changing password for user user2.
New password: 
BAD PASSWORD: The password is shorter than 7 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost ~]# 
[root@localhost ~]# id user2
uid=1001(user2) gid=1001(user2) groups=1001(user2)
[root@localhost ~]# 

linux sudoers 用户权限配置,linux,linux,运维,服务器


1.4、验证sudo 权限
# 把 user1 和 user2 添加到拥有超级管理员权限的组(wheel) 里
[root@localhost ~]# getent group wheel
wheel:x:10:   
[root@localhost ~]# 
[root@localhost ~]# usermod -aG wheel user1 // 添加 user1 用户到 wheel 组了
[root@localhost ~]# 
[root@localhost ~]# getent group wheel
wheel:x:10:user1    //  查看已经添加进去
[root@localhost ~]# 
[root@localhost ~]# usermod -aG wheel user2   // 添加 user2 用户到 wheel 组了
[root@localhost ~]# 
[root@localhost ~]# getent group wheel
wheel:x:10:user1,user2   //  查看已经添加进去
[root@localhost ~]# 

[root@localhost ~]# su - user1  // 登录到 user1 
[user1@localhost ~]$ 
[user1@localhost ~]$ cd /opt/
[user1@localhost opt]$ 
[user1@localhost opt]$ ll
total 0
-rw-r--r-- 1 root root 0 Jun 28 16:38 school
-rw-r--r-- 1 root root 0 Jun 28 17:13 test.txt
[user1@localhost opt]$ 
[user1@localhost opt]$ cp school user1.txt  // 复制一份会报错权限不够
cp: cannot create regular file ‘user1.txt’: Permission denied
[user1@localhost opt]$ 
[user1@localhost opt]$ sudo cp school user1.txt  // 使用sudo 复制

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for user1: # 提示输入密码。因为,没有在文件/etc/sudoers里的wheel组加上NOPASSWD
[user1@localhost opt]$ 
[user1@localhost opt]$ ll
total 0
-rw-r--r-- 1 root root 0 Jun 28 16:38 school
-rw-r--r-- 1 root root 0 Jun 28 17:13 test.txt
-rw-r--r-- 1 root root 0 Jun 28 17:55 user1.txt  # 创建成功
[user1@localhost opt]$ 

linux sudoers 用户权限配置,linux,linux,运维,服务器文章来源地址https://www.toymoban.com/news/detail-640804.html


[root@localhost ~]# su - user2  // 登录 user2 
[user2@localhost ~]$ 
[user2@localhost ~]$ cd /opt/
[user2@localhost opt]$ ll
total 0
-rw-r--r-- 1 root root 0 Jun 28 16:38 school
-rw-r--r-- 1 root root 0 Jun 28 17:13 test.txt
-rw-r--r-- 1 root root 0 Jun 28 17:55 user1.txt
[user2@localhost opt]$ 
[user2@localhost opt]$ cp school user2  # 复制school文件为 user2
cp: cannot create regular file ‘user2’: Permission denied # 报错权限不够
[user2@localhost opt]$ 
[user2@localhost opt]$ sudo cp school user2  # 添加sudo。不需要添加密码
[user2@localhost opt]$ 
[user2@localhost opt]$ ll
total 0
-rw-r--r-- 1 root root 0 Jun 28 16:38 school
-rw-r--r-- 1 root root 0 Jun 28 17:13 test.txt
-rw-r--r-- 1 root root 0 Jun 28 17:55 user1.txt
-rw-r--r-- 1 root root 0 Jun 28 18:19 user2
[user2@localhost opt]$ 


-rw-r--r-- 1 root root 0 Jun 28 17:13 test.txt
-rw-r--r-- 1 root root 0 Jun 28 17:55 user1.txt
-rw-r--r-- 1 root root 0 Jun 28 18:19 user2
[user2@localhost opt]$ 

到了这里,关于Linux中配置sudo用户访问权限的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Linux中普通用户使用sudo命令提示lin is not in the sudoers file. This incident will be reported.

    在使用Linux的过程中我们 普通用户使用sudo 可能遇到这样的提示 pp is not in the sudoers file. This incident will be reported. 这一问题原因是因为 etc 文件中的 sudoers 这个文件中没有这个用户 我们可以按照下面操作进行修改【 以下操作都用英文模式下操作,切记 】 使用root用户登录进来

    2024年01月23日
    浏览(33)
  • 【Linux】如何检查Linux用户是否具有sudo权限

    在Linux系统中,sudo(superuser do)是一个重要的命令,它允许普通用户以系统管理员的身份执行命令。了解用户是否拥有sudo权限对于系统管理和安全性来说是非常重要的。 技术名词解释 sudo :一种程序,用于Unix和类Unix操作系统中,允许用户以另一个用户的安全权限,通常是超

    2024年01月16日
    浏览(35)
  • Linux:给普通用户设置sudo权限

    1、修改配置文件 sudo 的英文全称是 super user do,即以超级用户(root 用户)的方式执行命令。用户是否拥有sudo命令的执行权限,要看是否在于 /etc/sudoers 文件进行了设置。 /etc/sudoers 是一个文本文件,有其特定的语法,不要直接用 vim 或者 vi 来进行编辑,而是采用 visudo 命令。

    2024年02月14日
    浏览(30)
  • Linux下给普通用户添加sudo使用权限

    Linux 下在创建用户之后,默认状态下是不允许普通用户执行 sudo 操作的,如果普通用户在执行 sudo 时,会发生错误: xxx is not in the sudoers file.  This incident will be reported. 如下图所示: 上述报错显示当前该用户没被添加至 sudoers 文件中,所以不能使用这个命令,所以我们使用

    2024年02月15日
    浏览(35)
  • Linux中普通用户如何使用sudo指令提升权限

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 目录 前言 普通用户为何无法使用sudo? 我们来看一下具体操作 总结 世上有两种耀眼的光芒,一种是正在升起的太阳,一种是正在努力学习编程的你!一个爱学编程的人。各位看官,我衷心的希望这篇博

    2024年01月24日
    浏览(28)
  • Linux系统添加用户并授权管理员(sudo)权限

    一方面是为了安全权限考虑、也是防止误操作。另一方面也是为了保证用户平时处于普通权限下。 1、添加用户 使用useradd命令添加用户 useradd -m kingbase 2、修改密码 给新添加的用户“kingbase”设置一个密码( 注:设置密码的时候linux系统默认会有密码复杂度规则 ) passwd king

    2024年02月16日
    浏览(40)
  • 【Linux】Centos7下给新用户添加sudo权限

    直入正题: 我们用adduser创建新用户后,这个新用户是没有使用sudo的权限的。 比如我们创建一个新用户fortest: 这个用户是没有使用sudo的权限的: 我们可以在root下修改( /etc/sudoers )这个路径下的文件sudoers解决。  我们可以看到这个文件是只读的, 根据我们之前学的权限的

    2024年02月07日
    浏览(75)
  • Linux系统知识4—Linux的root用户,su 和 exit 命令,sudo 命令,用户和用户组管理,getent,查看权限控制,修改权限控制 -chmod,修改权限控制-chown

    目录 一.Linux的root用户 1.1 root用户(超级管理员) 1.2 su 和 exit 命令 1.3 sudo 命令 1.为普通用户配置 sudo 认证 二.用户和用户组管理 2.1用户,用户组 2.2用户组的管理 2.3用户管理 2.4.getent 三.查看权限控制 3.1认知权限信息 1.序号1,表示文件,文件夹的权限控制信息 2. 序号2,表

    2024年01月17日
    浏览(47)
  • linux 服务器安装多版本 cuda (无 sudo 权限 非 root 用户也适用)

    linux 服务器安装多版本 cuda (无 sudo 权限 非 root 用户也适用) 下载想要版本的 cuda toolkit 下载对应版本 cudnn 以 cuda 10.0 为例 每个用户修改自己home目录下的 /bashrc 文件 对于无 sudo 权限 或者 非 root 用户,在安装第一步中安装cuda的时候,将cuda toolkit的安装路径设置为自己有权限

    2024年02月10日
    浏览(42)
  • 【Linux专区】如何配置新服务器 | 添加普通用户到sudoers | 配置vim | git免账号密码pull push

    💞💞 欢迎来到 Claffic 的博客 💞💞      👉  专栏 : 《Linux专区》👈 💬 前言: 时隔131天,你的好友Claffic重新发文了!(✿◕‿◕✿) 上期已经带大家白嫖了阿里云服务器,如果你还没有云服务器,请移步至【Linux专区】 环境搭建 | 带你白嫖七个月阿里云服务器_如何用

    2024年02月03日
    浏览(46)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包