Problem description:

there are two Macs, #2 one logged in with exampleuser and #1 I am logged in as admin.

exampleuser doesn't have SSH rights at all, as it isn't an administrator. admin has full rights and I also know the password for exampleuser.

What I want to do:

I want to open a Program via SSH on exampleusers Mac (#1).

As I tested it I gave exampleuser the rights and connected as exampleuser via SSH - everything worked just fine with "open /Applications/..." (But for security reasons I can't give exampleuser SSH access all the time).

What I did:

I used the admin account to connect to Mac #2 via SSH, but as I started the program, it obviously returned error as it's not the same user. So I tried "su exampleuser" but after that I wasn't really connected as exampleuser but instead I was somehow stuck in a strange bash that I've never seen before so it didn't work either.

So i thought about connecting as admin, then temporarily giving exampleuser ssh rights so as to connect directly, but i didn't find out how to change SSH-settings via SSH.

So how could I do it?

  • On most BSDs to use su you have to be in group wheel. Since OS X is somehow a BSD derivative I could imagine that's the problem. Another variant would be using sudo (with appropriate configuration). – Andreas Wiese Mar 26 '14 at 20:56
  • Sorry but maybe I didn't write it clear enough: the COMMAND su exampleuser works, but it just takes me to some strange bash, and I'm not really connected as exampleuser. – user300119 Mar 27 '14 at 5:22

The "su" command allows you to "switch user" context (including "super user"). I forget which S.U. gives "su" it's name.

When you run something after typing su <username>, you ARE running it as that user. However, you will not have the user's environment.

Try su - <username> instead. It will load the user's entire (command-line) environment. I assume you're running a command-line program, and not trying to open a GUI like MS Word or something.

  • Actually I was quite surprised that this method didn't work as I wanted to use it originally, but I got some strange bash shell. Normally the Shell shows PCNAME:~ USERNAME$ but after "su exampleuser" it only showed something like bash-3.1$ – user300119 Mar 28 '14 at 17:12
  • Actually I overlooked your second way, which worked perfectly as I wanted it to - thanks! – user300119 Jun 27 '14 at 14:10

Have you tried

su -c <command> <user>

su [OPTION]... [-] [USER [ARG]...]

Change the effective user id and group id to that of USER.

-, -l, --login
    make the shell a login shell 
-c, --command=COMMAND
    pass a single COMMAND to the shell with -c 
  • 1
    I'll try this one... But I have to wait until monday :-) – user300119 Mar 28 '14 at 17:17
  • Were you able to try the above suggestion out? – driz Apr 28 '14 at 21:28
  • I'm sorry I didn't answer for such a long time - I was that frustrated about the whole thing, I put it aside and didn't think about it until today as I found the working solution. – user300119 Jun 27 '14 at 14:11

I'm assuming that you're connected to Mac1 as you, exampleuser is logged on to Mac2, exampluser can SSH into Mac2 and that you know the password for exampleuser. Given that, you should be able to

[Mac1:~] $ ssh exampleuser:password@Mac2

Then you should be able to run the application with their context. If the app is GUI-based, you'll need to use the open command with the -a option.

[Mac2:~] $ open -a /Applications/Xcode.app
  • That would indeed be the solution except that out of security reasons I can't give exampleuser SSH rights all the time - not even to his own PC! I know It's kind of dumb but I really can't. – user300119 Mar 28 '14 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy