是否可以在 OS X Mountain Lion 下以不同用户身份运行软件?

fre*_*nte 7 terminal sudo bash osx-mountain-lion macos

我一直在尝试以不同的用户身份运行应用程序。

尝试 1
sudo -u otheruser open /Applications/TextEdit.app启动应用程序,但它使用当前用户,而不是otheruser

尝试2
login usernamesu - otheruser成功登录为otheruser,不同的用户活动监控器弹出,但类似open /Applications/TextEdit.app回报的错误LSOpenURLsWithRole() failed with error -10810 for the file /Applications/TextEdit.app.

尝试 3
sudo su - otheruser -c /Applications/TextEdit.app/Contents/MacOS/TextEdit似乎启动了该应用程序(它出现在由otheruser启动的 Activity Monitor 下)但是当停靠图标无限期地弹跳时会出现此错误:_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.

问题
那么……我如何以不同的用户身份运行应用程序?

小智 4

在 10.8 Mountain Lion 上,这个问题的答案对我来说似乎并不完全正确。我认为 demure 在第 2 点有一个打字错误,除了“-”之外肯定还有别的东西。对我有用的是:你的尝试 3,没有su-c

sudo -u testuser /Applications/TextEdit.app/Contents/MacOS/TextEdit
Run Code Online (Sandbox Code Playgroud)

这将作为测试用户打开 TextEdit,我可以将文件保存到/. 保存到 testuser 的用户文件夹不起作用,但这可能是因为我授予该帐户很少的权限,因为我将其用于其他测试目的。有趣的是,即使我在 KeyChain.app 中停用了 root 用户,我也可以以 root 身份登录。这似乎只影响从 root 登录桌面,而不影响终端登录。我保存为 testuser 的文件具有正确的拥有权限等设置。

$ cd /
$ ls -la | grep testuser
-rw-r--r--    1 testuser  staff      330 18 Okt 20:07 Untitled.rtf
Run Code Online (Sandbox Code Playgroud)

  • 是的,这对 MSTeams 不起作用 - 收到“错误:EACCES:权限被拒绝,uv_cwd”。编辑:更正,如果我在当前用户的主目录之外进行更改,此错误就会消失。 (2认同)