linux把普通用户加入sudoers,解决无法执行sudo,每次sudo都要输入密码,获取执行sudo权限,添加进入sudo用户组 您所在的位置:网站首页 系统管理里没有了用户组怎么办 linux把普通用户加入sudoers,解决无法执行sudo,每次sudo都要输入密码,获取执行sudo权限,添加进入sudo用户组

linux把普通用户加入sudoers,解决无法执行sudo,每次sudo都要输入密码,获取执行sudo权限,添加进入sudo用户组

2024-07-17 17:45| 来源: 网络整理| 查看: 265

开始使用debian时,发现不能使用sudo xxx is not in the sudoer file. the incident will be reported

3个解决方法 把自己加入到拥有sudo权限的用户组中,比如sudo这个组把用户名按照指定格式,加到/etc/sudoers文件把用户名按照指定格式,新建文件,加到/etc/sudoers.d文件夹中 方法一

就一句话:先su进入root,把xxx加入sudo组就可以了

su usermod -aG sudo xxx

因为sudo组的权限已经被系统设置好了,你查看一下/etc/sudoers,就可以看到里面有如下内容,这是系统内置的sudo组的权限设置。组名就叫sudo,加入此组,即可sudo

#Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL 方法二

把用户加到/etc/sudoers里面,但是/etc/sudoers是没有权限直接改的,需要先进入root

1.执行su,输入密码切换到root

2.执行(这里用vi vim pico nano等编辑器都一样,随便)

nano /etc/sudoers

3.看到最后有这样几行,按照root的格式加一行,即让自己拥有和root一样的权限,在最后一个ALL前面加上NOPASSWD: 就无需输入密码了

#User privilege specification root ALL=(ALL:ALL) ALL xxx ALL=(ALL:ALL) NOPASSWD:ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL

4.保存即可,vi vim一般是先按esc再输入:wq,nano是ctrl+o保存,ctrl+x退出

5.输入exit退出root,输入sudo,显示sudo用法,则当前用户已经可以使用sudo

方法三

其实,sudoers是一个只读文件,所以我们才要先进入root才能编辑。官方也不建议直接更改sudoers,它内容比较重要。

官方推荐在/etc/sudoers.d里面添加用户权限,是一样的效果,因为sudoers文件最后一行,用#include命令包含了/etc/sudoers.d的内容。

# See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d

所以我们可以先用su 进入root,在/etc/sudoers.d中新建一个文件,例如

su cd /etc/sudoers.d vim test

输入内容,xxx为你的用户名,保存即可

xxx ALL=(ALL:ALL) NOPASSWD:ALL 一些理解: xxx ALL = (ALL: ALL) NOPASSWD:ALL

用户名 主机名 =(用户名:用户组名)[执行命令是否需要密码]:[命令名称] (默认的是需要密码)



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有