Running As a Non-root User

Problem

You’d like to run your scripts as a non-root user, but are afraid you won’t be able to do the things you need to do.

Solution

Run your scripts under non-root user IDs, either as you or as dedicated users, and run interactively as non-root, but configure sudo to handle any tasks that require elevated privileges.

Discussion

sudo may be used in a script as easily as it may be used interactively. See the sudoers NOPASSWD option especially. See Using sudo More Securely.

Get bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.