Redhat – Run as different user

daemonredhatusers

On a RedHat system, i'm trying to launch a program with a different user who dont have any shell. In /etc/passwd, shell is /sbin/nologin.

I have tried:

  1. su myuser -c /home/myuser/script.sh
    Result: This account is currently not available.

  2. With chown and setuid:
    chown myuser:mygroup /home/myuser/script.sh
    chmod +s /home/myuser/script.sh
    /home/myuser/script.sh
    Result: script.sh is still executed as my signed in user (root).

Best Answer

try:

su myuser -s /bin/sh -c /home/myuser/script.sh