Do not set "root" as "NOPASSWD" in sudoers file

cat /etc/sudoers
  root    ALL=(ALL)ALL: ALL

do not change it to
  root    ALL=(ALL)NOPASSWD: ALL

Since root should always have a password. Then we could login by command "su"

-------------------------------

讲解sudo配置文件/etc/sudoers的格式。
# User privilege specification
root    ALL=(ALL) ALL
# Allow members of group sudo to execute any command after they have
# provided their password
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
#
#includedir /etc/sudoers.d
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
以上是我的Ubuntu10.04的默认/etc/sudoers文件。"#"开头的都是注释可以忽略。
首先用户需要转换成根用户并使用visudo命令打开/etc/sudoers文件。
讲解:root    ALL=(ALL) ALL
root表示被授权的用户,这里是根用户;
第一个ALL表示所有计算机;
第二个ALL表示所有用户;
第三个ALL表示所有命令;
全句的意思是:授权根用户在所有计算机上以所有用户的身份运行所有文件。
%admin ALL=(ALL) ALL同上面一样,只不过被授权的成了admin这个组。
通用格式
/etc/sudoers的通用格式为:
user  host  run_as  command
user:一位或几位用户,在/etc/group中可以用一个%代替它,组对象的名称一定要用百分号%开头。
host:一个或几个主机名;
run_as:作为哪个用户运行,常见选项是root和ALL
command:想让用户或组运行的一个或几个根级别命令。
例如:
hans   ALL=(root)   useradd,userdel
授权hans用户在所有计算机上以root身份运行useradd,userdel命令。
%smith  ALL=(ALL)  NOPASSWD:useradd,userdel
授权smith组全部成员在所有计算机上以所有用户的身份运行useradd,userdel命令;且运行时不必输入密码。
需要注意的是,当我们为用户定义可以运行的命令时,必须使用完整的命令路径。这样做是完全出于安全的考虑,如果我们给出的命令只是简单的userad
而非
/usr/sbin/useradd,那么用户有可能创建一个他自己的脚本,也叫做userad,然后放在它的本地路径中,如此一来他就能够通过这个名为
useradd的本地脚本,作为root来执行任何他想要的命令了。这是相当危险的

时间: 2024-09-20 21:37:13

Do not set "root" as "NOPASSWD" in sudoers file的相关文章

centos添加和删除用户及 xxx is not in the sudoers file.This incident will be reported.的解决方法

1.添加用户,首先用adduser命令添加一个普通用户,命令如下: #adduser tommy //添加一个名为tommy的用户 #passwd tommy   //修改密码 Changing password for user tommy. New UNIX password:     //在这里输入新密码 Retype new UNIX password:  //再次输入新密码 passwd: all authentication tokens updated successfully.

mqm is not in the sudoers file. This incident will be reported.

Linux下普通用户用sudo执行命令时报"xxx is not in the sudoers file.This incident will be reported"错误,解决方法就是在/etc/sudoers文件里给该用户添加权限.如下: 1.切换到root用户下 2./etc/sudoers文件默认是只读的,对root来说也是,因此需先添加sudoers文件的写权限,命令是: chmod u+w /etc/sudoers 3.编辑sudoers文件 vi /etc/sudoers

解决:xxx is not in the sudoers file.This incident will be reported.的解决方法

Linux中普通用户用sudo执行命令时报"xxx is not in the sudoers file.This incident will be reported"错误,解决方法就是在/etc/sudoers文件里给该用户添加权限.如下: 1.切换到root用户下  方法为直接在命令行输入:su,然后输入密码(即你的登录密码,且密码默认不可见). 2./etc/sudoers文件默认是只读的,对root来说也是,因此需先添加sudoers文件的写权限,命令是: 即执行操作:chmo

企业运维案例:xxx is not in the sudoers file.This incident will be reported” 错误解决方法

CentOS6系统下,普通用户使用sudo执行命令时报错: xxx is not in the sudoers file.This incident will be reported" 解决方法就是在/etc/sudoers文件里给该用户添加权限.如下: 1.切换到root用户下 2./etc/sudoers文件默认是只读的,对root来说也是,因此需先添加sudoers文件的写权限,命令是:chmod u+w /etc/sudoers 3.编辑sudoers文件vim /etc/sudoers

Linux中普通用户用sudo执行命令时报”xxx is not in the sudoers file.This incident will be reported”错误

Linux中普通用户用sudo执行命令时报"xxx is not in the sudoers file.This incident will be reported"错误,解决方法就是在/etc/sudoers文件里给该用户添加权限.如下: 1.切换到root用户下 方法为直接在命令行输入:su,然后输入密码(即你的登录密码,且密码默认不可见). 2./etc/sudoers文件默认是只读的,对root来说也是,因此需先添加sudoers文件的写权限,命令是: 即执行操作:chmod

ubuntu:xxx is not in the sudoers file. 问题解决

ubuntu 下普通用户用 sudo 执行命令时报 "xxx is not in the sudoers file.This incident will be reported" 错误,解决方法是在 /etc/sudoers 文件里给该用户添加权限.操作过程如下: 1. 切换到 root 用户下 2. /etc/sudoers 文件默认是只读的,对 root 来说也是,因此需先添加 sudoers 文件的写权限,命令是: chmod u+w /etc/sudoers 3. 编辑 sud

xxx is not in sudoers file 解决(转)

解决方案:首需要切换到root身份$su -(注意有- ,这和su是不同的,在用命令"su"的时候只是切换到root,但没有把root的环境变量传过去,还是当前用户的环境变量,用"su -"命令将环境变量也一起带过去,就象和root登录一样) 然后$visudo     //切记,此处没有vi和sudo之间没有空格 1.移动光标,到最后一行2.按a,进入append模式3.输入your_user_name ALL=(ALL)  ALL4.按Esc5.输入“:wq”(

is not in the sudoers file解决方法

用sudo时提示"xxx is not in the sudoers file. This incident will be reported.其中XXX是你的用户名,也就是你的用户名没有权限使用sudo,我们只要修改一下/etc/sudoers文件就行了. 下面是修改方法:1)进入超级用户模式.也就是输入"su -",系统会让你输入超级用户密码,输入密码后就进入了超级用户模式.(当然,你也可以直接用root用) 2)添加文件的写权限.也就是输入命令"chmod u

is not in the sudoers file.This incident will be reported

解决方法如下: 1>.进入超级用户模式.也就是输入"su -",系统会让你输入超级用户密码,输入密码后就进入了超级用户模式. 2>.添加文件的写权限.也就是输入命令"chmod u+w /etc/sudoers". 3>.编辑/etc/sudoers文件.也就是输入命令"vim /etc/sudoers",输入"i"进入编辑模式,找到这一行:"root ALL=(ALL) ALL"在起下面