Skip to main content
Grammar. Also added bold to draw the eye to the second (and principal) part of the answer.
Source Link

Both su orand sudo can do this. They run a command as another user; by default that "another user" is root, but it can be any user, for. For example,

sudo -u www-data ls 

will run ls as the user www-data.

However...


However...

The usual way is to run the script as the invoking user and use sudo for those commands which need it. sudo caches the credentials, so it should prompt at most once.

Both su or sudo can do this. They run a command as another user; by default that "another user" is root, but it can be any user, for example

sudo -u www-data ls 

will run ls as the user www-data.

However...

The usual way is to run the script as the invoking user and use sudo for those commands which need it. sudo caches the credentials, so it should prompt at most once.

Both su and sudo can do this. They run a command as another user; by default that "another user" is root, but it can be any user. For example,

sudo -u www-data ls 

will run ls as the user www-data.


However...

The usual way is to run the script as the invoking user and use sudo for those commands which need it. sudo caches the credentials, so it should prompt at most once.

Added a hint for better practice
Source Link
AlexP
  • 10.8k
  • 37
  • 44

Both su or sudo can do this. They run a command as another user; by default that "another user" is root, but it can be any user, for example

sudo -u www-data ls 

will run ls as the user www-data.

However...

The usual way is to run the script as the invoking user and use sudo for those commands which need it. sudo caches the credentials, so it should prompt at most once.

Both su or sudo can do this. They run a command as another user; by default that "another user" is root, but it can be any user, for example

sudo -u www-data ls 

will run ls as the user www-data.

Both su or sudo can do this. They run a command as another user; by default that "another user" is root, but it can be any user, for example

sudo -u www-data ls 

will run ls as the user www-data.

However...

The usual way is to run the script as the invoking user and use sudo for those commands which need it. sudo caches the credentials, so it should prompt at most once.

Source Link
AlexP
  • 10.8k
  • 37
  • 44

Both su or sudo can do this. They run a command as another user; by default that "another user" is root, but it can be any user, for example

sudo -u www-data ls 

will run ls as the user www-data.