没有权限时在Mac上编辑sudoers文件

时间:2012-07-09 14:06:18

标签: permissions sudo sudoers

我试图在我的Mac上安装一些东西但我没有获得许可,因为我不是管理员。所以我尝试使用sudo,它说我不在sudoers文件中。我已经尝试过编辑sudoers文件,但它不会让我,所以我用谷歌搜索了#34;它。每个人都说使用visudo来编辑文件。问题是,它甚至不让我使用visudo!当我输入" visudo"它只是说

visudo: /etc/sudoers: Permission denied

会感激一些帮助。提前谢谢!

编辑:我尝试切换用户然后编辑sudoers文件但仍然无法正常工作

4 个答案:

答案 0 :(得分:2)

您需要root(或拥有root权限才能使用visudo命令并编辑sudoers文件

答案 1 :(得分:0)

如果你搞砸了你的sudoers文件。你需要:

  • 重新启动进入恢复模式(在启动时点击退出,在grub屏幕上选择恢复模式选项)
  • 选择“启用网络”选项(如果不是,您的文件系统将以只读方式挂载。谁知道)
  • 选择'Drop to root shell'选项
  • 运行visudo,修复您的文件
  • 使用普通grub选项重新启动

来源: - http://mario.net.au/content/recover-etcsudoers-ubuntu-1204

答案 2 :(得分:0)

您必须是root用户或使用sudo编辑sudoers文件。

sudo visudo

答案 3 :(得分:0)

I am new to mac. Very annoyed by the time=0 for sudoer (you havew to type the password every time you use sudo). I want to increase this value to a reasonable number: timestamp_timeout=30. After adding the above line to the /etc/sudoers file, I could not login as su anymore because the parser fails to read the sudoers file. This posting is to document how I fix this problem.

1. Restart your mac
2. Hold on to Command-R two keys until you see the progress bar.
3. Start a new terminal, this terminal will be the root terminal
4. Edit the invalid sudoers file.  Note this file is not in /etc/sudoers when you loggedin in as root

The full path is: /Volumes/Macintosh HD/etc restart then you are happy again.

This method will also apply to users who are not in the sudoers list and want to add themselves to the list.

Note: if you could not find the sudoers file as root use find:

find / -name sudoers