在使用sudo 执行命令时,每次都要输入密码比较的麻烦,我们可以通过修改/etc/sudoers
文件配置
sudo 执行命令时不需要输入密码。
步骤:
- 切换目录到etc 下 命令:
cd /etc
- 查看 sudoers 权限 命令:
ls -l sudoers
-r--r----- 1 root root 787 7月 30 14:38 sudoers
- 修改sudoers权限 加入可写权限 命令:
sudo chmod +w sudoers
ls -l sudoers
-rw-r----- 1 root root 787 7月 30 14:38 sudoers
- 打开修改文件配置 命令:
sudo vi sudoers
/etc$ sudo vi sudoers
-------------------------------------------------------------------
# User privilege specification
root ALL=(ALL:ALL) ALL
xx ALL=(ALL) NOPASSWD: ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
xx ALL=(ALL) NOPASSWD: ALL
image.png
不知道用户名在终端中输入
whoami
查询
- 修改sudoers权限删除可写权限 命令:
sudo chmod -w sudoers
大功告成!!!
================================================================
有visudo这个东西,这种方法非常安全,执行
$sudo visudo
找到
%admin ALL=(ALL) ALL
注释之,在下面加上
%admin ALL=(ALL) NOPASSWD: ALL
意思是属于admin组的用户可以不需要输入密码执行sudo
如果是
admin ALL=(ALL) NOPASSWD: ALL
也就是去掉百分号,意思就是admin这个用户可以执行sudo
这样做的好处是避免了输入错误,如果出错,退出之后会提示你出错,按e重新编辑,不会出现进不了sudo的情况,安全了很多.