Skip to main content
edited body
Source Link

It is possible to let httpd (or any other user) be able to issue a specific command or run any specific service as any other (system)user without actually having sudo privileges.

In this case, assume apache runs with the www-data account:

In order to do this on Ubuntu do the following:
$ sudo vi /etc/sudoers.d/www-data
www-data ALL=(ALL) NOPASSWD: /usr/bin/crontab, NOPASSWD: /usr/bin/whoami, NOPASSWD: /bin/bash /home/steam/webstart.sh [[\:alpha\:]]*

Explanation:
What this does is create a file named www-data in the /etc/sudoers.d location. The file says that the www-data user is allowed, and ONLY allowed, to run "/usr/bin/crontab", "/usr/bin/whoami" and "/bin/bash /home/steam/webstart.sh" with sudo.

This means, that www-data can sudo start webstart.sh, which contains a script that in turn will start a service. This will run under the "steam" user account, and you don't need to give root privileges to the service.

-rwxrwxr-x 1 steam steam 123 Feb 15 14:52 webstart.sh

Note:
[[\:alpha\:]]* means that the webstart.sh command can be followed by any alphabetical letter, so you can pass arguments to the script. Without this, www-data would not even be allowed to run "/bin/bash /home/steam/webstart.sh a" as this is NOT what was specified. The sudoers is VERY strict and literal. If you want, you can specify exactly which command is allowed. If multiple commands are specifically allowed, you must add multiple statements seperated by comma's: NOPASSWD: /bin/bash /home/steam/webstart.sh start, NOPASSWD: /bin/bash /home/steam/webstart.sh stop, NOPASSWD: /bin/bash /home/steam/webstart.sh restart

Warning: Make sure NOT to add NOPASSWD: /bin/bash [[\:alpha\:]]* without specifying a command or script before the regex, as this would allow www-data to run /bin/bash followed by ANY command, obviously.

PS: It is not necesarry to actually name the file www-data, but I like to make a separate file for each user which I grant special privileges instead of combining them all into one.

It is possible to let httpd (or any other user) be able to issue a specific command or run any specific service as any other (system)user without actually having sudo privileges.

In this case, assume apache runs with the www-data account:

In order to do this on Ubuntu do the following:
$ sudo vi /etc/sudoers.d/www-data
www-data ALL=(ALL) NOPASSWD: /usr/bin/crontab, NOPASSWD: /usr/bin/whoami, NOPASSWD: /bin/bash /home/steam/webstart.sh [[\:alpha\:]]*

Explanation:
What this does is create a file named www-data in the /etc/sudoers.d location. The file says that the www-data user is allowed, and ONLY allowed, to run "/usr/bin/crontab", "/usr/bin/whoami" and "/bin/bash /home/steam/webstart.sh" with sudo.

This means, that www-data can sudo start webstart.sh, which contains a script that in turn will start a service. This will run under the "steam" user account, and you don't need to give root privileges to the service.

-rwxrwxr-x 1 steam steam 123 Feb 15 14:52 webstart.sh

Note:
[[\:alpha\:]]* means that the webstart.sh command can be followed by any alphabetical letter, so you can pass arguments to the script. Without this, www-data would not even be allowed to run "/bin/bash /home/steam/webstart.sh a" as this is NOT what was specified. The sudoers is VERY strict and literal. If you want, you can specify exactly which command is allowed. If multiple commands are specifically allowed, you must add multiple statements seperated by comma's: NOPASSWD: /bin/bash /home/steam/webstart.sh start, NOPASSWD: /bin/bash /home/steam/webstart.sh stop, NOPASSWD: /bin/bash /home/steam/webstart.sh restart

PS: It is not necesarry to actually name the file www-data, but I like to make a separate file for each user which I grant special privileges instead of combining them all into one.

It is possible to let httpd (or any other user) be able to issue a specific command or run any specific service as any other (system)user without actually having sudo privileges.

In this case, assume apache runs with the www-data account:

In order to do this on Ubuntu do the following:
$ sudo vi /etc/sudoers.d/www-data
www-data ALL=(ALL) NOPASSWD: /usr/bin/crontab, NOPASSWD: /usr/bin/whoami, NOPASSWD: /bin/bash /home/steam/webstart.sh [[\:alpha\:]]*

Explanation:
What this does is create a file named www-data in the /etc/sudoers.d location. The file says that the www-data user is allowed, and ONLY allowed, to run "/usr/bin/crontab", "/usr/bin/whoami" and "/bin/bash /home/steam/webstart.sh" with sudo.

This means, that www-data can sudo start webstart.sh, which contains a script that in turn will start a service. This will run under the "steam" user account, and you don't need to give root privileges to the service.

-rwxrwxr-x 1 steam steam 123 Feb 15 14:52 webstart.sh

Note:
[[\:alpha\:]]* means that the webstart.sh command can be followed by any alphabetical letter, so you can pass arguments to the script. Without this, www-data would not even be allowed to run "/bin/bash /home/steam/webstart.sh a" as this is NOT what was specified. The sudoers is VERY strict and literal. If you want, you can specify exactly which command is allowed. If multiple commands are specifically allowed, you must add multiple statements seperated by comma's: NOPASSWD: /bin/bash /home/steam/webstart.sh start, NOPASSWD: /bin/bash /home/steam/webstart.sh stop, NOPASSWD: /bin/bash /home/steam/webstart.sh restart

Warning: Make sure NOT to add NOPASSWD: /bin/bash [[\:alpha\:]]* without specifying a command or script before the regex, as this would allow www-data to run /bin/bash followed by ANY command, obviously.

PS: It is not necesarry to actually name the file www-data, but I like to make a separate file for each user which I grant special privileges instead of combining them all into one.

edited body
Source Link

It is possible to let httpd (or any other user) be able to issue a specific command or run any specific service as any other (system)user without actually having sudo privileges.

In this case, assume apache runs with the www-data account:

In order to do this on Ubuntu do the following:
$ sudo vi /etc/sudoers.d/www-data
www-data ALL=(ALL) NOPASSWD: /usr/bin/crontab, NOPASSWD: /usr/bin/whoami, NOPASSWD: /bin/bash /home/steam/webstart.sh [[\:alpha\:]]*

Explanation:
What this does is create a file named www-data in the /etc/sudoers.d location. The file says that the www-data user is allowed, and ONLY allowed, to run "/usr/bin/crontab", "/usr/bin/whoami" and "/bin/bash /home/steam/webstart.sh" with sudo.

This means, that www-data can sudo start webstart.sh, which contains a script that in turn will start a service. This will run under the "steam" user account, and you don't need to give root privileges to the service.

-rwxrwxr-x 1 steam steam 123 Feb 15 14:52 webstart.sh

Note:
[[\:alpha\:]]* means that the webstart.sh command can be followed by any alphabetical letter, so you can pass arguments to the script. Without this, www-data would not even be allowed to run "/bin/bash /home/steam/webstart.sh a" as this is NOT what was specified. The sudoers is VERY strict and literal. If you want, you can specify exactly which command is allowed. If multiple commands are specifically allowed, you must add multiple statements seperated by comma's: NOPASSWD: /bin/bash /home/steam/webstart.sh start, NOPASSWD: /bin/bash /home/steam/webstart.sh stop, NOPASSWD: /bin/bash /home/steam/webstart.sh restart

PS: It is not necesarry to actually name the file www-data, but I like to make a seperateseparate file for each user which I grant special privileges instead of combining them all into one.

It is possible to let httpd (or any other user) be able to issue a specific command or run any specific service as any other (system)user without actually having sudo privileges.

In this case, assume apache runs with the www-data account:

In order to do this on Ubuntu do the following:
$ sudo vi /etc/sudoers.d/www-data
www-data ALL=(ALL) NOPASSWD: /usr/bin/crontab, NOPASSWD: /usr/bin/whoami, NOPASSWD: /bin/bash /home/steam/webstart.sh [[\:alpha\:]]*

Explanation:
What this does is create a file named www-data in the /etc/sudoers.d location. The file says that the www-data user is allowed, and ONLY allowed, to run "/usr/bin/crontab", "/usr/bin/whoami" and "/bin/bash /home/steam/webstart.sh" with sudo.

This means, that www-data can sudo start webstart.sh, which contains a script that in turn will start a service. This will run under the "steam" user account, and you don't need to give root privileges to the service.

-rwxrwxr-x 1 steam steam 123 Feb 15 14:52 webstart.sh

Note:
[[\:alpha\:]]* means that the webstart.sh command can be followed by any alphabetical letter, so you can pass arguments to the script. Without this, www-data would not even be allowed to run "/bin/bash /home/steam/webstart.sh a" as this is NOT what was specified. The sudoers is VERY strict and literal. If you want, you can specify exactly which command is allowed. If multiple commands are specifically allowed, you must add multiple statements seperated by comma's: NOPASSWD: /bin/bash /home/steam/webstart.sh start, NOPASSWD: /bin/bash /home/steam/webstart.sh stop, NOPASSWD: /bin/bash /home/steam/webstart.sh restart

PS: It is not necesarry to actually name the file www-data, but I like to make a seperate file for each user which I grant special privileges instead of combining them all into one.

It is possible to let httpd (or any other user) be able to issue a specific command or run any specific service as any other (system)user without actually having sudo privileges.

In this case, assume apache runs with the www-data account:

In order to do this on Ubuntu do the following:
$ sudo vi /etc/sudoers.d/www-data
www-data ALL=(ALL) NOPASSWD: /usr/bin/crontab, NOPASSWD: /usr/bin/whoami, NOPASSWD: /bin/bash /home/steam/webstart.sh [[\:alpha\:]]*

Explanation:
What this does is create a file named www-data in the /etc/sudoers.d location. The file says that the www-data user is allowed, and ONLY allowed, to run "/usr/bin/crontab", "/usr/bin/whoami" and "/bin/bash /home/steam/webstart.sh" with sudo.

This means, that www-data can sudo start webstart.sh, which contains a script that in turn will start a service. This will run under the "steam" user account, and you don't need to give root privileges to the service.

-rwxrwxr-x 1 steam steam 123 Feb 15 14:52 webstart.sh

Note:
[[\:alpha\:]]* means that the webstart.sh command can be followed by any alphabetical letter, so you can pass arguments to the script. Without this, www-data would not even be allowed to run "/bin/bash /home/steam/webstart.sh a" as this is NOT what was specified. The sudoers is VERY strict and literal. If you want, you can specify exactly which command is allowed. If multiple commands are specifically allowed, you must add multiple statements seperated by comma's: NOPASSWD: /bin/bash /home/steam/webstart.sh start, NOPASSWD: /bin/bash /home/steam/webstart.sh stop, NOPASSWD: /bin/bash /home/steam/webstart.sh restart

PS: It is not necesarry to actually name the file www-data, but I like to make a separate file for each user which I grant special privileges instead of combining them all into one.

added 231 characters in body
Source Link

It is possible to let httpd (or any other user) be able to issue a specific command or run any specific service as any other (system)user without actually having sudo privileges.

In this case, assume apache runs with the www-data account:

In order to do this on Ubuntu do the following:
$ sudo vi /etc/sudoers.d/www-data
www-data ALL=(ALL) NOPASSWD: /usr/bin/crontab, NOPASSWD: /usr/bin/whoami, NOPASSWD: /bin/bash /home/steam/webstart.sh [[\:alpha\:]]*

Explanation:
What this does is create a file named www-data in the /etc/sudoers.d location. The file says that the www-data user is allowed, and ONLY allowed, to run "/usr/bin/crontab", "/usr/bin/whoami" and "/bin/bash /home/steam/webstart.sh" with sudo. /home/steam/webstart.sh is chown steam:steam. This

This means, that www-data can sudo start webstart.sh, which contains a script that in turn will start thea service with. This will run under the "steam" user account. This way, and you don't need to give root privileges to anythe service running.

-rwxrwxr-x 1 steam steam 123 Feb 15 14:52 webstart.sh

Note:
[[\:alpha\:]]* means that the webstart.sh command can be followed by any alphabetical letter, so you can pass arguments to the script. Without this, www-data would not even be allowed to run "/bin/bash /home/steam/webstart.sh a" as this is NOT what was specified. The sudoers is VERY strict and literal. If you want, you can specify exactly which command is allowed. If multiple commands are specifically allowed, you must add multiple statements seperated by comma's: NOPASSWD: /bin/bash /home/steam/webstart.sh start, NOPASSWD: /bin/bash /home/steam/webstart.sh stop, NOPASSWD: /bin/bash /home/steam/webstart.sh restart

PS: It is not necesarry to actually name the file www-data, but I like to make a seperate file for each user which I grant special privileges instead of combining them all into one.

It is possible to let httpd (or any other user) be able to issue a specific command or run any specific service as any other (system)user without actually having sudo privileges.

In this case, assume apache runs with the www-data account:

In order to do this on Ubuntu do the following:
$ sudo vi /etc/sudoers.d/www-data
www-data ALL=(ALL) NOPASSWD: /usr/bin/crontab, NOPASSWD: /usr/bin/whoami, NOPASSWD: /bin/bash /home/steam/webstart.sh [[\:alpha\:]]*

Explanation:
What this does is create a file named www-data in the /etc/sudoers.d location. The file says that the www-data user is allowed, and ONLY allowed, to run "/usr/bin/crontab", "/usr/bin/whoami" and "/bin/bash /home/steam/webstart.sh" with sudo. /home/steam/webstart.sh is chown steam:steam. This means, that www-data can sudo start webstart.sh which in turn will start the service with the "steam" user account. This way, you don't need to give root to any service running.

Note:
[[\:alpha\:]]* means that the webstart.sh command can be followed by any alphabetical letter, so you can pass arguments to the script. Without this, www-data would not even be allowed to run "/bin/bash /home/steam/webstart.sh a" as this is NOT what was specified. The sudoers is VERY strict and literal. If you want, you can specify exactly which command is allowed. If multiple commands are specifically allowed, you must add multiple statements seperated by comma's: NOPASSWD: /bin/bash /home/steam/webstart.sh start, NOPASSWD: /bin/bash /home/steam/webstart.sh stop, NOPASSWD: /bin/bash /home/steam/webstart.sh restart

PS: It is not necesarry to actually name the file www-data, but I like to make a seperate file for each user which I grant special privileges instead of combining them all into one.

It is possible to let httpd (or any other user) be able to issue a specific command or run any specific service as any other (system)user without actually having sudo privileges.

In this case, assume apache runs with the www-data account:

In order to do this on Ubuntu do the following:
$ sudo vi /etc/sudoers.d/www-data
www-data ALL=(ALL) NOPASSWD: /usr/bin/crontab, NOPASSWD: /usr/bin/whoami, NOPASSWD: /bin/bash /home/steam/webstart.sh [[\:alpha\:]]*

Explanation:
What this does is create a file named www-data in the /etc/sudoers.d location. The file says that the www-data user is allowed, and ONLY allowed, to run "/usr/bin/crontab", "/usr/bin/whoami" and "/bin/bash /home/steam/webstart.sh" with sudo.

This means, that www-data can sudo start webstart.sh, which contains a script that in turn will start a service. This will run under the "steam" user account, and you don't need to give root privileges to the service.

-rwxrwxr-x 1 steam steam 123 Feb 15 14:52 webstart.sh

Note:
[[\:alpha\:]]* means that the webstart.sh command can be followed by any alphabetical letter, so you can pass arguments to the script. Without this, www-data would not even be allowed to run "/bin/bash /home/steam/webstart.sh a" as this is NOT what was specified. The sudoers is VERY strict and literal. If you want, you can specify exactly which command is allowed. If multiple commands are specifically allowed, you must add multiple statements seperated by comma's: NOPASSWD: /bin/bash /home/steam/webstart.sh start, NOPASSWD: /bin/bash /home/steam/webstart.sh stop, NOPASSWD: /bin/bash /home/steam/webstart.sh restart

PS: It is not necesarry to actually name the file www-data, but I like to make a seperate file for each user which I grant special privileges instead of combining them all into one.

added 231 characters in body
Source Link
Loading
Source Link
Loading