All I need to do is to run a specific script as a particular 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.
root:root -rwsr-x---? – Patryk Mar 10 '15 at 00:24su -s /bin/bash -c 'exec /path/to/your/script &' test– Facundo Victor Apr 27 '16 at 12:59runuser, I'd like to point out thatsu -s SHELLparameter renders runuser command pretty much useless :) Thanks Jan! – Jiri Jul 21 '16 at 18:06sudo su -s ...– Calimo Dec 12 '16 at 12:45runuseris preferable. It is compatible whithsu. – user3132194 Mar 12 '18 at 11:30-sisn't an option – Ray Foss Jul 19 '18 at 14:29nginx -ttozabbixuser via sudoers, and want to test the commandsudo /usr/sbin/nginx -t. You can runsu -s /bin/bash -c 'sudo /usr/sbin/nginx -t' zabbix, even whenzabbixuser hasnologinas shell. – ivanleoncz May 26 '20 at 00:28