Mac sudo: /etc/sudoers is owned by uid 501, should be 0
$ sudo -s
sudo: /etc/sudoers is owned by uid 501, should be 0
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
You can boot into single user mode by pressing Cmd-S on startup
see OS X: How to start up in single-user or verbose mode for details
which should give you a root shell. Then run
mount -uw /
chown root:wheel /etc/sudoers
chown root:wheel /private/etc/sudoers.d/
chmod 440 /etc/sudoers
reboot
to fix the problem and restart.
Mac 设置 root权限
sudo passwd root
然后提示输入当前登录用户密码,通过以后提示输入两遍root的密码。
homer$ sudo passwd root
sudo: /private/etc/sudoers.d is owned by uid 501, should be 0
Changing password for root.
New password:
Retype new password:
$ su root
Password:
sh-3.2#
sh-3.2#
这样就设置好root帐号密码了,可以用root来登录MacOS了
Mac OS X 终端切换 root 用户
方法一:
1. 打开Terminal
2. $ sudo -i
3. 输入root密码即可
方法二:
和方法一中1和3步相同,只是第二步输入的命令不是sudo -i 而是sudo su或是su。
区别:
方法一和方法二的区别是获取root权限后终端显示的不一样。
方法一是这样的:
yanggangdeMacBook-Pro:~ homer$ sudo -i
yanggangdeMacBook-Pro:~ root#
方法二是这样的:
yanggangdeMacBook-Pro:~ homer$ sudo su
sh-3.2#
sh-3.2# exit
exit
yanggangdeMacBook-Pro:~ homer$ su // 需要先设置root密码
Password:
sh-3.2#
sh-3.2#
/etc/suoders 查看访问权限
$ ls -l /etc/sudoers
-r--r----- 1 root wheel 1645 6 17 19:17 /etc/sudoers
wheel和staff用户组
传统unix系统中,wheel用户组是管理员组,只有该组的成员才可以通过su获取root权限。wheel实际上已经成了管理员组的代名词。
staff 是系统全体用户(普通用户),所有的系统用户都是staff组的成员,因此改变文件的组权限为staff,则所有的用户都具有了相应的权限。
/etc/suoders 文件编辑
/etc/sudoers 文件必须是root管理员,且使用 visudo 编辑器
# This file MUST be edited with the 'visudo' command as root.
曾经,为了是sudo 不输入密码,visudo 修改如下:
# root and users in group wheel can run anything on any machine as any user
root ALL = (ALL) ALL
%admin ALL = (ALL) ALL
%sudo ALL = (ALL) NOPASSWD:ALL
%wheel ALL = (ALL) NOPASSWD:ALL
后来,发现sudo -s 切换管理权限,速度非常慢,于是注释掉了
# root and users in group wheel can run anything on any machine as any user
root ALL = (ALL) ALL
%admin ALL = (ALL) ALL
#%sudo ALL = (ALL) NOPASSWD:ALL
#%wheel ALL = (ALL) NOPASSWD:ALL
sudo -s 执行速度就快乐好多,所以一般不要改动系统级的超级管理权限文件
否则,有一天你的Mac电脑无法启动开机,别怪我没提醒过你哈,呵呵呵。
参考推荐:
修改服务器默认远程端口(阿里云)
Linux ssh 切换登录用户自动转到root用户 (推荐)
Linux shell 脚本通过expect实现自动输入密码
版权所有: 本文系米扑博客原创、转载、摘录,或修订后发表,最后更新于 2018-10-13 20:40:12
侵权处理: 本个人博客,不盈利,若侵犯了您的作品权,请联系博主删除,莫恶意,索钱财,感谢!
转载注明: Mac sudo: /etc/sudoers is owned by uid 501, should be 0 (米扑博客)