Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

All I need to do is to run a specific script as a particual user who does have the nologin/false shell indicated in /etc/passwd.

I would run the script as root and this should run as another user. Running :~# su -c "/bin/touch /tmp/test" testuser would work but I need a valid shell for the testuser. I know I can disable the password with passwd -d testuser and leave the shell to /bin/bash this way would secure a little bit but I need to have nologin/false shell.

Basically what I need is what crontab does when we set jobs to be running as a particular user, regardless this one has nologin/false shell.

p.s I found this thread Executing a command as a nologin user but I have no idea how to "concatenate" the command su -s /bin/sh $user to the script I need to run

Thanks

share|improve this question

4 Answers 4

You can use the -s switch to su to run a particular shell

su -s /bin/bash -c '/path/to/your/script' testuser
share|improve this answer

just realized :

su -s "/bin/bash" -c "/bin/touch /tmp/testuser" testuser

maybe there is a better way ?!

share|improve this answer

By providing the script as the argument to execute to /bin/sh:

su -s "/bin/sh /your/script/location" username
share|improve this answer

You can do this with sudo -u if you have it installed:

# whoami
root
# sudo -u apache whoami
apache
# getent passwd apache
apache:x:48:48:Apache:/var/www:/sbin/nologin
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.