I am trying to run a command as another user in Linux. Here is what I run:
su user1 -c '/bin/mkdir /tmp/zz'
However, this gives me this error:
fatal: unrecognized command '/bin/mkdir /tmp/zz'
I am trying to run a command as another user in Linux. Here is what I run:
su user1 -c '/bin/mkdir /tmp/zz'
However, this gives me this error:
fatal: unrecognized command '/bin/mkdir /tmp/zz'
You need to swap the single quotes for double quotes. Not that these are only required with commands that take parameters, or if you chain several commands together.
su user1 -c "/bin/mkdir /tmp/zz"
As suggested by Mark Wagner, I encountered the same problem when the user had a non-standard shell (in my case it was git-shell). And the solution was to do:
su -s /bin/bash -c 'some command'