十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
说明:
sudo命令的执行流程是: 当前用户转换到root, 然后以root身份执行命令, 执行完成后, 直接退回到当前用户.
需要注意的是: 执行sudo时输入的密码, 是当前用户的密码, 并非root密码
1、修改文件写权限
# ls -l /etc/sudoers
-r--r----- 1 root root 4042 Nov 4 15:05 /etc/sudoers
# chmod u+x /etc/sudoers
# vi /etc/sudoers
# ls -l /etc/sudoers
2、添加免密用户
vi /etc/sudoers
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
## add MySQL user
mysql ALL=(ALL) NOPASSWD: ALL
3、sudo免密测试
[mysql@devdb01 ~]$ sudo ip addr
1: lo: mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:87:3b:bd brd ff:ff:ff:ff:ff:ff
inet 1x2.55.3.xx/24 brd 196.55.3.255 scope global eth0
inet6 fe80::250:56ff:fe87:3bbd/64 scope link
valid_lft forever preferred_lft forever
[mysql@devdb01 ~]$