日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

解决 Linux 系统,出现“不在sudoers文件中,此事将被报告”的问题

發布時間:2023/12/8 linux 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 解决 Linux 系统,出现“不在sudoers文件中,此事将被报告”的问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我在使用個人用戶(非root用戶)時,在執行其他命令時,使用sudo命令來執行的時候,需要驗證當前用戶的密碼,輸入了之后,提示“admin 不在sudoers文件中,此事將被報告”

分析原因,主要是權限不夠,需要提升權限。

解決方法:

步驟:

1、先切換至root用戶,輸入命令:su root,然后輸入密碼

[admin@localhost ~]$ su root
密碼:

?

2、查看?/etc/sudoers?文件權限,如果只讀權限,修改為可寫權限

輸入查看文件命令:ls –l /etc/sudoers

[root@localhost admin]# ll /etc/sudoers
-r--r-----. 1 root root 4355 11月 24 11:13 /etc/sudoers

?

由此可看,該文件為只讀權限

3、設置?/etc/sudoers?文件權限,添加 可寫權限

輸入修改權限命令:chmod u+w /etc/sudoers

[root@localhost admin]# chmod u+w /etc/sudoers

4、執行vim命令,編輯/etc/sudoers文件,

輸入編輯文件命令:"vim /etc/sudoers"

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

5、查看打印內容

E325: 注意
發現交換文件 "/etc/.sudoers.swp"
? ? ? ? ? ? 所有者: root ? ?日期: Wed Nov 24 11:10:17 2021
? ? ? ? ? ? 文件名: /etc/sudoers
? ? ? ? ? ? 修改過: 是
? ? ? ? ? ? 用戶名: root ? ? ?主機名: localhost
? ? ? ? ? ?進程 ID: 4637 (仍在運行)
正在打開文件 "/etc/sudoers"
? ? ? ? ? ? ? 日期: Wed Nov 24 11:39:36 2021
? ? ? 比交換文件新!

(1) Another program may be editing the same file. ?If this is the case,
? ? be careful not to end up with two different instances of the same
? ? file when making changes. ?Quit, or continue with caution.
(2) An edit session for this file crashed.
? ? 如果是這樣,請用 ":recover" 或 "vim -r /etc/sudoers"
? ? 恢復修改的內容 (請見 ":help recovery")。
? ? 如果你已經進行了恢復,請刪除交換文件 "/etc/.sudoers.swp"
? ? 以避免再看到此消息。

交換文件 "/etc/.sudoers.swp" 已存在!
以只讀方式打開([O]), 直接編輯((E)), 恢復((R)), 退出((Q)), 中止((A)):
?

6、按e鍵,直接編輯

7、利用?回車鍵?換行,找到?Allow root to run any commands anywhere?,按i鍵開始編輯,下面的指令會出現插入的字樣。

8、在root ALL=(ALL) ALL?的下一行添加代碼:admin ALL=(ALL) ALL

## 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
admin ? 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
?

9、按?ESC?鍵退出插入模式,然后 鍵盤輸入?:wq?關閉并保存

## 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
admin ? 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

:wq

10、恢復?/etc/sudoers的權限為440

輸入回復權限的命令:chmod 440 /etc/sudoers

[root@localhost admin]# chmod 440 /etc/sudoers

11、查看/etc/sudoers的權限是否恢復

輸入查看權限命名:ll /etc/sudoers

[root@localhost admin]# ll /etc/sudoers
-r--r-----. 1 root root 4355 11月 24 11:41 /etc/sudoers

12、權限恢復正常,切換至普通用戶

輸入切換用戶命令:su admin

[root@localhost admin]# su admin
[admin@localhost ~]$?

13、測試該用戶的權限,我們可以使用命令?sudo useradd user1?來創建新用戶

[admin@localhost? ~]$ sudo useradd user1

14、此時已經沒有了先去的報錯,用戶也已經創建成功,大功告成!!!

總結

以上是生活随笔為你收集整理的解决 Linux 系统,出现“不在sudoers文件中,此事将被报告”的问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。