How to run a script as another user (without password) on Linux

Probably, it’s one of the most common tasks: running some scripts as another user and not being root. Here’s a solution.

1. Run visudo. If you don’t have it make sure you have sudo installed.

2. Add next line:

myuser ALL=(anotheruser) NOPASSWD: /home/anotheruser/bin/

3. Run:

sudo -u anotheruser /home/anotheruser/bin/