How do I run a script with admin rights using OS X

11 次查看(过去 30 天)
I'm trying to install ecg-kit on OS X el captain and I have to run a script called 'InstallECGKit.m'with admin/root privileges. I've just bought a Mac and a little unfamiliar with OS. For the life of me, I can't figure out how to do this simple thing.
I will be very helpful for any guidance!
Thanks!
  1 个评论
Walter Roberson
Walter Roberson 2016-3-2
This is tricky to do. Normally you would go to a Terminal window and use "sudo" to start the binary you want to run with elevated privileges. However, if you try to do that with MATLAB, it will complain that your userid does not match the entry in the license file.
I found a utility somewhere named LaunchAsRoot and I am able to start MATLAB from that, but I am not certain that I get admin privileges this way; the evidence I saw suggested not.

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2016-3-2
Can you gain admin privileges to the current user?
  1 个评论
Walter Roberson
Walter Roberson 2016-3-2
Not easily, not in OS-X or Linux. Although there are secure Linux systems where individual access rights can be allocated to a non-root user, the traditional form of access privileges is to change the effective userid to 0 (root) -- and if you do that then MATLAB says "Oh, your email address does not match".
If the script just needs to write some regular files or directories into a place the user would not normally have access to, then the easiest mechanism is to give the user access. That can be done by temporarily changing permissions to allow "other" to access, or in OS-X can be done by using chmod to add ACL (Access Control List).
But if the script needs to reconfigure the kernel, then you have a problem.
Depending how the script is written, it might be easiest to change the script so that each time it needs to do something privileged, it uses system('sudo ...') -- because sudo remembers user authentication for a period of time so that the first password prompt to the user would typically be sufficient to allow everything to finish.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by