macos 在 Mac 上的终端窗口中切换用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5671046/
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
Switch user in a terminal window on a Mac
提问by user633101
Could anybody help with simple question.
I need login/switch user in command line in 1 line; For example:
login -p username ? password
.
任何人都可以帮助解决简单的问题。我需要在命令行中的 1 行登录/切换用户;例如:
login -p username ? password
。
What should I write at '?' position? Because I need to login in script which don't know id system asked password...
我应该在'?'写什么 位置?因为我需要在不知道 id 系统要求密码的脚本中登录...
回答by ppolyzos
回答by Jonathan Leffler
You should probably investigate sudo
.
你应该调查一下sudo
。
回答by Anne
You can provide the password to sudo like this:
您可以像这样向 sudo 提供密码:
echo "p@sw0rd" | sudo -S cal -y 2011
The example above runs 'cal -y 2011' with root permissions.
上面的示例以 root 权限运行“cal -y 2011”。
回答by prodigitalson
Im pretty sure you cant use login
non-interactively (same for su
) unless youre logging in as the already logged in user or unless the login
command is invoked by root. However, if you meet either one of those requirements you would use the -f
switch.
我很确定您不能以login
非交互方式使用(与 相同su
),除非您以已经登录的用户身份登录,或者除非该login
命令由 root 调用。但是,如果您满足其中任何一个要求,则可以使用该-f
开关。
man
Page: http://www.manpagez.com/man/1/login/
man
页面:http: //www.manpagez.com/man/1/login/
you could of course use ssh
but it seems wrong to ssh locally... You could also use expect
to script the interactive login process.
您当然可以使用,ssh
但在本地 ssh 似乎是错误的...您也可以使用expect
脚本来编写交互式登录过程。