If I do
su - -c 'mkdir bin' user1
then I get
su: /usr/bin/ksh: No such file or directory
because the users shell is set to ksh
in /etc/passwd
and ksh
is not installed.
Question
How do I carry commands out as the user in such a case?
If I do
su - -c 'mkdir bin' user1
then I get
su: /usr/bin/ksh: No such file or directory
because the users shell is set to ksh
in /etc/passwd
and ksh
is not installed.
Question
How do I carry commands out as the user in such a case?
If you don't put the
-
aftersu
then it won't load that user's environment, but the commands will still be run as that user.It appears that I misunderstood your actual problem. As other have said
-s
is the option you probably actually want.You can use:
The
-s
option to su specifies the shell to use, overriding whatever is in /etc/passwd.I dropped the
-
from your command because, in addition to loading the profile, it will probably change the working directory to the home directory of the user for the command, so you'd be creating 'bin' in user1's home directory, not your current directory.I believe the -s/--shell option to su lets you pick the shell to use while keeping the other parts of users environment, /bin/sh is specified by posix so should be available everywhere.