sudo免密输入

编辑/etc/sudoers配置文件

1
2
chmod u+w /etc/sudoers
vim /etc/sudoers

75 ## Uncomment to allow members of group wheel to execute any command
76 %wheel ALL=(ALL) ALL

检查配置文件

1
2
chmod u-w /etc/sudoers
visudo -c -f /etc/sudoers

查看id属性

1
2
id XXX
uid=1000(XXX) gid=100(users) 组=474(vboxusers),100(users)

添加用户到wheel组

1
sudo usermod -a -G wheel XXX

检查id属性

1
2
id XXX
uid=1000(XXX) gid=100(users) 组=474(vboxusers),10(wheel),100(users)

查看组

1
2
groups 
users vboxusers

添加当前用户的配置到/etc/sudoers.d/

1
sudo visudo -f /etc/sudoers.d/XXXpwd

查看/etc/sudoers.d/XXXpwd配置文件内容

1
2
3
sudo cat /etc/sudoers.d/XXXpwd
Defaults env_keep += "DISPLAY XAUTHORITY"
Defaults !targetpw

添加xorg显示配置

1
2
visudo -f sudoers.d/xorg
Defaults env_keep += "DISPLAY XAUTHORITY"

这个好像没起作用

添加xorg显示配置的系统变量

1
vim profile.local
1
2
LANG=zh_CN.UTF-8
export XAUTHORITY=~/.Xauthority

添加到用户变量(dup升级可能无法登入桌面环境)

~/.bashrc配置加上:
export XAUTHORITY=~/.Xauthority

显示当前用户的sudo内容

1
2
3
4
sudo -l

用户 XXX 可以运行以下命令:
(ALL) NOPASSWD: /usr/bin/zypper, /usr/bin/rsync, /usr/sbin/cryptsetup, /usr/sbin/hdparm

版权声明: 署名非商用CC BY-NC 4.0