黑帽联盟

标题: linux普通用户执行sudo不需要密码 [打印本页]

作者: yun    时间: 2017-2-3 23:11
标题: linux普通用户执行sudo不需要密码
要求普通用户输入sudo的时候,不需要密码.

  系统:centos 6.3

1.设置普通用户可以使用sudo
chmod u+w /etc/sudoers

vi /etc/sudoers
找到这行 root ALL=(ALL) ALL,在他下面添加
username ALL=(ALL)                NOPASSWD: ALL

再找到下面这句
#%wheel  ALL=(ALL)         NOPASSWD: ALL
改成
%wheel  ALL=(ALL)         NOPASSWD: ALL
保存退出后执行:

gpasswd -a username wheel
将你的用户(普通用户)调整至wheel用户组里面,这样就可以以后用户执行sudo就不用输入密码了.

2.恢复/etc/sudoers的权限
因为我没有把/etc/sudoers的权限恢复成440,就切换到普通用户下去执行:
sudo ifconfig
报以下错误:
sudo: /etc/sudoers is mode 0640, should be 0440
sudo: no valid sudoers sources found, quitting
退出普通用户,在root下执行:
chmod u-w /etc/sudoers

chmod 440 /etc/sudoers

再到普通用户执行
sudo ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 22:00:0A:84:05:83
          inet addr:10.132.5.11  Bcast:10.132.5.191  Mask:255.255.255.192
          inet6 addr: fe80::2000:aff:fe84:583/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6034 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4242 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:657163 (641.7 KiB)  TX bytes:669943 (654.2 KiB)
          Interrupt:246

可以看到执行sudo成功了.





欢迎光临 黑帽联盟 (https://bbs.cnblackhat.com/) Powered by Discuz! X2.5