这个问题是我在用普通用户安装软件包时遇到的。这里分享一下。

问题场景

[fenghx@localhost ~]$ sudo yum install freetds我们信任您已经从系统管理员那里了解了日常注意事项。
总结起来无外乎这三点:#1) 尊重别人的隐私。#2) 输入前要先考虑(后果和风险)。#3) 权力越大,责任越大。[sudo] fenghx 的密码:
fenghx 不在 sudoers 文件中。此事将被报告。
[fenghx@localhost ~]$

fenghx是我新建的一个系统用户,当用fenghx用户登陆系统后,使用 sudo 安装 freetds 时,提示:fenghx 不在 sudoers 文件中。此事将被报告

问题解决

Linux系统上安装软件需要使用root权限,普通用户要想安装软件需要提升自己的权限,此时需要使用sudo命令,能使用这个命令的用户必须在sudo用户列表中,即sudoers系统配置文件中。所以需要将 fenghx 用户配置到sudoers系统配置文件中。

1. 切换到root用户

命令:su - root

[fenghx@localhost ~]$ su - root
密码:
上一次登录:五 2月 10 09:27:10 CST 2023从 xxx.xxx.xxx.xxxpts/0 上Welcome to BigCloud Enterprise Linux 7 (GNU/Linux 3.10.0-1127.19.1.el7.x86_64 x86_64)System information as of Fri Feb 10 09:56:52 CST 2023* System CPU load:  0.25 0.12 0.08        * System   uptime:     09:56:52 up 2 days * Active sessions:  3                     * Memory    usage:     2127 / 7990 MB* Processes count:   399* Get Support  :* Ask Questions:http://forum.bclinux.org* Contact US   :MAIL : support@bclinux.org / TEL : 4001-10086-558 packages can be updated.
0 updates are security updates.
type 'yum check-update --security' to see details.
[root@localhost ~]#

2. 打开sudoers文件查看,路径:/etc/sudoers

命令:vim /etc/sudoers

[root@localhost ~]# vim /etc/sudoers

打开文件如下所示:

# Adding HOME to env_keep may enable a user to run unrestricted
# commands via sudo.
#
# Defaults   env_keep += "HOME"Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
##      user    MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)       ALL## Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL## Allows members of the users group to mount and unmount the
## cdrom as root
# %users  ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom## Allows members of the users group to shutdown this system
# %users  localhost=/sbin/shutdown -h now## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d
-- 插入 -- W10: 警告: 正在修改一个只读文件

当我准备修改文件配置的时候,进入编辑状态时,最下面命令栏提示:W10:警告:正在修改一个只读文件,也就是说当前的这个系统配置文件没有写的权限。那么就需要修改文件权限再编辑。

3. 修改系统配置文件sudoers

命令:chmod u+w /etc/sudoers      #其中 u+w的意思是:给当前用户添加写操作权限,即给root用户添加修改sudoers文件的权限。

[root@localhost ~]# ls -al /etc/sudoers
-r--r-----. 1 root root 4328 11月 28 2019 /etc/sudoers
[root@localhost ~]# chmod u+w /etc/sudoers
[root@localhost ~]# ls -al /etc/sudoers
-rw-r-----. 1 root root 4328 11月 28 2019 /etc/sudoers
[root@localhost ~]# vim /etc/sudoers

上面先查看了 sudoers 文件的权限,发现只有读的权限,于是用 chmod 命令添加了写的权限,然后打开文件编辑如下,此时就不会提示上面只读文件的警告了。

## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
##      user    MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
fenghx  ALL=(ALL)       ALL## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)       ALL## Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL## Allows members of the users group to mount and unmount the
## cdrom as root
# %users  ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom## Allows members of the users group to shutdown this system
# %users  localhost=/sbin/shutdown -h now## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
-- 插入 --

## Allow root to run any commands anywhere 提示信息的下面的 root行 之后添加你要执行sudo命令的用户,其它和root行内容一样即可,注意:列于列之间用 tab 符分割
保存文件后退出,然后我们用普通用户先来执行关闭防火墙的命令,看能否成功。

4. 验证是否修改成功

[root@localhost ~]# su - fenghx
上一次登录:五 2月 10 13:48:13 CST 2023pts/0 上
[fenghx@localhost ~]$ sudo systemctl stop firewalld
[sudo] fenghx 的密码:
[fenghx@localhost ~]$ sudo firewall-cmd --state
not running
[fenghx@localhost ~]$

以上命令中,先从root用户切换到普通用户fenghx,然后用sudo命令关闭防火墙,发现可以执行,并且没有提示“fenghx 不在 sudoers 文件中。此事将被报告。”的告警信息。并且通过查看防火墙状态,发现确实关闭了,到这里就说明我们已经将普通用户添加到了sudo列表中,可以正常的使用sudo命令来临时提升自己的权限。

验证完之后我们需要重启防火墙。并修改系统配置文件 sudoers 为只读的权限。

[fenghx@localhost ~]$ sudo systemctl start firewalld
[fenghx@localhost ~]$ sudo firewall-cmd --state
running
[fenghx@localhost ~]$ sudo chmod u-w /etc/sudoers
[fenghx@localhost ~]$ sudo ls -al /etc/sudoers
-r--r-----. 1 root root 4350 2月  10 13:51 /etc/sudoers
[fenghx@localhost ~]$

接着在 fenghx 普通用户下,使用 sudo 命令安装软件的时候就可以安装了。


好了,分享完毕,希望帮到你,谢谢阅览。

Linux之用户不在 sudoers 文件中。此事将被报告。相关推荐

  1. 用户不在 sudoers 文件中此事将被报告

    "用户不在 sudoers 文件中此事将被报告". 出现这个提示,就是这个用户没法得到超级用户权限 sudo的具体执行流程如下: 当用户执行sudo时,系统会自动寻找/etc/su ...

  2. Debian11镜像更新为阿里巴巴开源镜像站镜像,切换root用户,解决用户名不在sudoers文件中此事将被报告,Debian11 文件夹对话框、火狐浏览器、命令终端等没有最大化和最小化

    选择Debian作为编程开发最佳Linux的理由: Debian是面向程序员的最古老,最出色的Linux发行版之一.Debian提供了具有.deb软件包管理兼容性的超稳定发行版.Debian为程序员提 ...

  3. xxx不在 sudoers 文件中,此事将被报告

    执行sudo apt install ***, 输入密码后提示: xxx不在不在 sudoers 文件中,此事将被报告. 问题的原因是我们在安装时没有将用户添加为管理员. 切换超级用户 su # 切换 ...

  4. 用户名不在sudoers文件中此事将被报告的解决方法

    用户名不在sudoers文件中此事将被报告的解决方法 参考文章: (1)用户名不在sudoers文件中此事将被报告的解决方法 (2)https://www.cnblogs.com/yongfengni ...

  5. 【Linux】用户不在sudoers文件中

    *** is not in the sudoers file.  This incident will be reported."  (用户不在sudoers文件中--) 处理这个问题很简单 ...

  6. linux中 不在sudoers文件中此事将被报告

    1.切换到root用户下 2. 打开/etc/sudoers文件,注意此文件的权限!!! 3. 更改文件内容: root ALL=(ALL) ALL 用户名 ALL=(ALL) ALL

  7. 解决“不在sudoers文件中此事将被报告 不能切换root权限“

    参考1: https://blog.csdn.net/m0_59133441/article/details/121511380 我是通过上面这个解决的.说一下我的过程. 开始我使用usermod把我 ...

  8. 用户不在 sudoers文件中,此事将被报告。

    记录一下遇见的这个问题,感谢这位博主 用户 不在 sudoers 文件中.此事将被报告._邹奇健身已上瘾-CSDN博客_用户不在sudoers文件中此事将被报告https://blog.csdn.ne ...

  9. Linux “用户不在 sudoers 文件中。此事将被报告“的解决方法

    普通用户在执行系统程序时,需要临时提升权限,sudo在需要输入当前用户密码便可以临时提升权限 但是并非所有用户都能够执行sudo,因为有此权限的用户都在/etc/sudoers文件中进行了配置 如果没 ...

最新文章

  1. 码流 / 码率 / 比特率 / 帧速率 / 分辨率 / 高清
  2. 看动画学算法之:排序-快速排序
  3. C#调用ORACLE存储过程返回结果集及函数
  4. LeetCode之Maximum Depth of Binary Tree
  5. tableau 倒序都倒了_Tableau优秀作品拆解复刻01-是时候终结瘘管病了
  6. [转载] Python语言程序设计基础(第二版)嵩天等课后习题答案
  7. Firemonkey使用Android原生控件一些注意事项
  8. Arduino基础学习-SG90舵机的使用
  9. linux 卸载oracle库,Linux下完美卸载 Oracle
  10. Y430P拆机:安装固态硬盘+内存+重装系统梳理
  11. [家里蹲大学数学杂志]第409期与正弦对数有关的一个积分不等式
  12. 最后一公里极速配送(一)
  13. 直播app开发搭建,纯css/html实现侧边导航栏
  14. 项目进度经常延误,该怎么破?
  15. 如何成为一名正义黑客?你应该学习什么?
  16. 折线迷你图怎么设置_Excel2013如何使用迷你图展示数据?
  17. VC++中遇到的错误“Error spawning cl.exe”
  18. 禁止文件夹 icloud_如何更改Windows iCloud照片文件夹位置
  19. ios11.2计算机更新,iOS11.2.2正式版怎么样、更新了什么?iOS11.2.2降频吗?
  20. mysql 安装启动服务器一直失败_mysql安装后服务器启动失败的几种解决办法

热门文章

  1. Redhat虚拟机根目录扩容
  2. 连连看项目实战之三(解析配置表)
  3. JavaScript学习之HTML-demo
  4. iOS高仿微信、仪表盘、图片标注图片滤镜、高斯模糊、上拉加载、下拉刷新等源码
  5. SVN merge(合并) 时看不到以前的已经合并过的记录的标识
  6. 什么是TLB文件,怎样从dll文件中提取TYPEID信息?- IID
  7. TIM学习文档20-- 权限管理
  8. ECharts数据可视化学习笔记和应用
  9. curl编程实例——文件下载
  10. 【论文指导】计算机毕业设计,摘要如何写?15篇案例把你安排明白