mac sudo: /etc/sudoers is world writable

自从Mac版本升级之后,各种不适应,service 命令竟然没了,百度了一下说是要修改/etc/sudoers  ,在使用 chmod -R 777 /etc/sudoers 之后问题就来了,我竟然无法切换root用户,现在记录一下,解决办法

1.在Mac中启动root 账户

https://jingyan.baidu.com/article/49711c619e7620fa441b7ca8.html

2.切换到root用户,修改 /etc/sudoers的权限

#无法使用chmod修改权限
demo:Desktop piaoyu.qiu$ ls -la /etc/sudoers
-rwxrwxrwx  1 root  wheel  1371  8  9 11:28 /etc/sudoers
demo:Desktop piaoyu.qiu$ chmod 440 /etc/sudoers
chmod: Unable to change file mode on /etc/sudoers: Operation not permitted

#切换到root用户
demo:Desktop piaoyu.qiu$ su
Password:你自己设置的密码
sh-3.2# ls -l /etc/sudoers
-rwxrwxrwx  1 root  wheel  1371  8  9 11:28 /etc/sudoers
sh-3.2# chmod 0440 /etc/sudoers
sh-3.2# ls -l /etc/sudoers
-r--r-----  1 root  wheel  1371  8  9 11:28 /etc/sudoers
sh-3.2# exit