macos 如何在 Mac OS X 上以 root 身份运行脚本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/74829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:53:32  来源:igfitidea点击:

How to run a script as root on Mac OS X?

macosterminal

提问by Mac

What should I type on the Mac OS X terminal to run a script as root?

我应该在 Mac OS X 终端上输入什么来以 root 身份运行脚本?

回答by dF.

As in any unix-based environment, you can use the sudocommand:

与在任何基于 unix 的环境中一样,您可以使用以下sudo命令:

$ sudo script-name

It will ask for your password (your own, not a separate rootpassword).

它会询问您的密码(您自己的密码,而不是单独的root密码)。

回答by Rob B

Or you can access root terminal by typing sudo -s

或者您可以通过键入 sudo -s 来访问 root 终端

回答by Hymanrabbit

In order for sudo to work the way everyone suggest, you need to be in the admingroup.

为了让 sudo 按照每个人建议的方式工作,您需要加入该admin组。

回答by Bob Wintemberg

sudo ./scriptname

须藤 ./脚本名

回答by Dana

sudo ./scriptname

须藤 ./脚本名

sudo bash will basically switch you over to running a shell as root, although it's probably best to stay as su as little as possible.

sudo bash 基本上会将您切换到以 root 身份运行 shell,尽管最好尽可能少地保持 su。