Skip to main content

Linux Sudoer Policy

Overview

The Linux Sudoer Policy lets administrators centrally manage which users and groups can run commands through sudo on managed Linux devices.

With this policy, you can:

  • Allow or deny specific commands

  • Apply rules to individual users or groups

  • Limit rules to particular hosts

  • Define the user or group a command can run as

  • Require or omit password authentication

  • Match an exact command argument list

  • Verify an executable using its SHA-256 digest

  • Apply NOEXEC and SETENV sudoers tags

  • Use rule priorities to resolve overlapping permissions

This policy supports least-privilege access by granting users only the administrative commands required for their roles.

Important: Incorrect sudoers rules can grant unintended root access or prevent administrators from performing recovery tasks. Test every policy on a nonproduction device before broad deployment.

Requirements

Requirement

Details

Supported platform

Linux

Ownership types

Company-owned and BYOD

Device management

The device must be enrolled in Swif

Sudo

A compatible sudo implementation must be installed

Identity resolution

Configured users, groups, hosts, and netgroups must be resolvable on the device

Agent connectivity

The Swif agent must be online to receive the policy

Behavior can vary by Linux distribution, installed sudo version, identity provider, and local sudoers configuration.

Before You Begin

Before creating a policy:

  1. Identify the exact users or groups that require elevated access.

  2. Determine the minimum commands required for each role.

  3. Find the absolute path of every executable.

  4. Identify any required command arguments.

  5. Decide which target user or group the command must run as.

  6. Confirm whether passwordless execution is necessary.

  7. Check whether users can modify the executable, script, arguments, configuration files, or directories involved.

  8. Review existing files in /etc/sudoers and /etc/sudoers.d/ for conflicting permissions.

  9. Keep a recovery account or console-access method outside the policy.

  10. Test the configuration on a representative device.

Use the following command to find an executable’s resolved path:

command -v systemctl

Example result:

/usr/bin/systemctl

Always configure the absolute path instead of relying on the user’s PATH.

Create the Policy

  1. In the Swif Admin Dashboard, go to Device Management > Policies.

  2. Create a new policy.

  3. Select Linux Sudoer Policy.

  4. Enter a descriptive policy name.

  5. Add one or more sudoer rules.

  6. Configure the subjects, hosts, run-as identities, commands, authentication, and hardening settings.

  7. Assign the policy to a test device or test group.

  8. Allow the device to sync.

  9. Verify the effective sudo permissions.

  10. Expand the assignment only after testing succeeds.

Recommended Configuration

Use the following baseline for most deployments:

Setting

Recommended value

Enabled

Enabled

Priority

100, with higher values reserved for exceptions

Subjects

A dedicated role-based group

Hosts

all, unless host-level restrictions are required

Run As Users

Explicitly specify the required user, commonly root

Run As Groups

Leave empty unless a target group is required

Command Effect

allow only for required commands

Command Path

Exact absolute executable path

Arguments

Exact arguments whenever practical

SHA-256

Configure for stable, security-sensitive executables

Require Password

Enabled

No Exec

Enabled when compatible with the command

Set Environment

Disabled

Avoid rules that combine all users, all hosts, unrestricted commands, root, and passwordless authentication.


Policy Settings

Sudoer Rules

A policy can contain multiple sudoer rules. Each rule defines:

  • Who receives the permission

  • Where the permission applies

  • Which identity the command runs as

  • Which commands are allowed or denied

  • Whether authentication is required

  • Which hardening tags are applied

Separate unrelated administrative tasks into different rules. This makes permissions easier to audit, test, and revoke.

Rule ID

The Rule ID uniquely identifies the rule.

Use a stable, descriptive identifier when this field is configurable, for example:

restart-nginx

or:

helpdesk-journal-access

Do not reuse the same identifier for unrelated rules.

Enabled

Controls whether the rule is active.

Value

Behavior

Enabled

Swif applies the rule to assigned devices.

Disabled

The rule remains in the policy but is not active.

The default value is enabled.

Disable a rule when temporarily suspending access without deleting its configuration.

Priority

Controls which rule takes precedence when multiple Swif sudoer rules overlap.

Higher values have higher priority. The default value is:

100

A practical priority model is:

Priority range

Suggested use

100

Standard role permissions

200

Device- or group-specific exceptions

300

Restrictive overrides or emergency rules

Use consistent priority ranges across your organization. Avoid assigning different priorities without documenting why they are needed.

Important: Priority resolves conflicts between Swif-managed rules. Existing local sudoers entries or rules delivered by another management product may still affect the user’s effective access.

Subjects

Subjects identify the users or groups to which a rule applies.

Each subject contains a Type and Value.

Type

Value

Description

user

Applies the rule to an individual user.

group

Applies the rule to members of a group.

Value

Enter the exact username or group name recognized by Linux.

Examples:

alice
linux-helpdesk

Prefer role-based groups over individual user rules. Group-based access is generally easier to review and revoke as responsibilities change.

Before deployment, confirm that the identity resolves correctly:

id alice
getent group linux-helpdesk

For identities supplied by LDAP, Active Directory, SSSD, or another directory service, test name resolution while the device is connected to the required network.

Hosts

Hosts determine where a rule applies.

Each host entry contains a Type and Value.

Host Type

Value

Description

all

Applies to any host receiving the policy.

hostname

Applies when the device matches the specified hostname.

ip

Applies when the device matches the specified IP address.

netgroup

Applies according to the specified network group.

Host Value

Enter the hostname, IP address, or netgroup required by the selected type.

The value is optional when Type is all.

Example for all assigned devices:

Setting

Value

Type

all

Value

Leave empty

Example for a named host:

Setting

Value

Type

hostname

Value

web-server-01

Host restrictions depend on the device resolving and reporting the expected identity. Consider DHCP changes, multiple network interfaces, short and fully qualified hostnames, and directory-service availability.

Netgroup matching requires working netgroup resolution on the device. Test it before deployment:

getent netgroup linux-admin-hosts

Run As

The Run As settings define the users and groups under which the subject may execute the configured commands.

Users

Enter one or more target usernames.

The most common target is:

root

However, commands should run as a less-privileged service account when root access is unnecessary.

Example:

postgres

Groups

Enter one or more target groups when the command must run with a specific group identity.

Leave this field empty if the user does not need to select a target group.

Explicitly configure the required run-as identities. Avoid granting access to a broad set of target users or groups.

Commands

Each command entry defines an allowed or denied executable and can include an exact argument list and SHA-256 digest.

Effect

Value

Description

allow

Permits the matching command.

deny

Prevents the matching command from being authorized by the applicable rule.

Use allow entries to build a narrow permission set. Use deny entries when you must exclude a specific command from a broader Swif-managed permission.

When allow and deny rules overlap, review their priorities and test the resulting permission on the device.

Important: A deny rule does not necessarily remove access granted independently through another local sudoers file, another management product, or direct root-group membership.

Path

Enter the executable’s absolute path.

Example:

/usr/bin/systemctl

Do not enter only:

systemctl

The executable path alone does not necessarily limit what the program can do. Shells, editors, interpreters, package managers, service managers, and programs that load user-controlled configuration can provide indirect ways to execute other commands.

High-risk examples include:

/bin/bash
/usr/bin/sh
/usr/bin/python3
/usr/bin/perl
/usr/bin/vim
/usr/bin/find
/usr/bin/less
/usr/bin/env
/usr/bin/sudo

Granting unrestricted access to these programs can be equivalent to granting a root shell.

Arguments

Use Arguments to require an exact argument list for the command match.

For example, to allow only a restart of the NGINX service:

Setting

Value

Path

/usr/bin/systemctl

Arguments

restart, nginx.service

This should authorize:

sudo /usr/bin/systemctl restart nginx.service

It should not authorize unrelated actions such as:

sudo /usr/bin/systemctl restart ssh.service

Enter arguments in their expected order. Differences in spelling, order, paths, options, or service names can prevent a match.

Do not assume that shell wildcard characters, variables, redirection, pipes, or command substitution are interpreted safely. Use literal, narrowly scoped arguments and test the exact command users will run.

Security warning: Allowing a service restart can still be dangerous if the user can modify the service unit, executable, environment file, configuration, plugin directory, or startup script.

SHA-256

Optionally enter the executable’s SHA-256 digest. When configured, the executable must match the specified digest.

Generate a digest on the target platform with:

sha256sum /usr/local/sbin/approved-maintenance

Example output:

d2a4c86dbd0f3bcf851d86fd0ef081f966640b7859fa7cbd69e8e15cc14f7c4f  /usr/local/sbin/approved-maintenance

Enter only the digest value.

Leave this field empty when hash verification is not required.

A digest can reduce the risk of an executable being replaced, but it has operational tradeoffs:

  • Updating the executable changes its digest.

  • The rule must be updated after an approved software upgrade.

  • A digest does not make unsafe arguments or writable configuration secure.

  • The executable and its parent directories must still be protected from unauthorized modification.

  • Scripts and interpreters require additional review because the interpreter, script, imports, and referenced files may all affect execution.

The sudoers documentation also warns that executable digest checks can be undermined if the user can modify the command during execution. Keep privileged executables and their directories writable only by trusted administrators. See the Ubuntu sudoers manual.

Authentication

Require Password

Controls whether sudo requires password authentication for the rule.

Value

Sudoers behavior

Enabled

Applies PASSWD; authentication is required according to the device’s sudo configuration.

Disabled

Applies NOPASSWD; the command can run without a password prompt.

The default value is enabled.

Recommended value:

Enabled

Use passwordless access only for a documented automation or operational requirement. A passwordless rule increases the impact of a compromised user session, account, or process.

Before disabling password authentication:

  • Restrict the rule to a dedicated account or group.

  • Allow only the required executable and arguments.

  • Prevent the subject from modifying the executable or related files.

  • Apply an executable digest when operationally appropriate.

  • Review logs and monitor use of the privileged command.

  • Confirm that the command cannot open a shell or execute arbitrary code.

Password authentication does not replace least-privilege command restrictions. Depending on the device’s sudo timestamp configuration, a recently authenticated user may not be prompted again for a period of time.

Hardening

No Exec

When enabled, No Exec applies the NOEXEC sudoers tag. It is intended to prevent an allowed program from launching additional executables.

Recommended value:

Enabled

Enable it when compatible with the approved command, especially for interactive programs that might otherwise provide shell escapes.

NOEXEC is a defense-in-depth control, not a complete sandbox. Its effectiveness depends on operating-system and program behavior, and it may not prevent every form of code execution. It can also break applications that legitimately start helper programs.

Test the complete workflow after enabling it.

Set Environment

When enabled, Set Environment applies the SETENV sudoers tag and permits the user to set or preserve environment variables that sudo would otherwise restrict.

Recommended value:

Disabled

Environment variables can change library loading, interpreter behavior, configuration paths, plugin discovery, and command execution. Enabling SETENV can turn an otherwise limited command into a privilege-escalation path.

Enable it only when:

  • A documented application requires it.

  • The allowed variables and command behavior have been reviewed.

  • The executable and its supporting files are trusted.

  • The rule is narrowly limited to the required users, hosts, paths, and arguments.

For more information about environment handling, see the Ubuntu sudoers manual.

Configuration Examples

Allow a Group to Restart NGINX

This example allows members of web-operators to restart only nginx.service as root.

Setting

Value

Enabled

Enabled

Priority

100

Subject Type

group

Subject Value

web-operators

Host Type

all

Run As Users

root

Effect

allow

Path

/usr/bin/systemctl

Arguments

restart, nginx.service

Require Password

Enabled

No Exec

Enabled

Set Environment

Disabled

Before deploying, confirm that members of the group cannot modify the NGINX service unit, executable, configuration, or loaded modules.

Allow a Monitoring Command Without a Password

This example allows a monitoring account to run one approved status command noninteractively.

Setting

Value

Enabled

Enabled

Priority

100

Subject Type

user

Subject Value

monitoring-agent

Host Type

all

Run As Users

root

Effect

allow

Path

/usr/local/sbin/check-service-health

Arguments

--output, json

SHA-256

Digest of the approved executable

Require Password

Disabled

No Exec

Enabled

Set Environment

Disabled

The script or executable, its parent directory, and every file it loads must be protected from modification by monitoring-agent.

Restrict a Rule to One Host

This example grants access only on a specific server.

Setting

Value

Subject Type

group

Subject Value

database-operators

Host Type

hostname

Host Value

database-01

Run As Users

postgres

Effect

allow

Path

/usr/bin/psql

Require Password

Enabled

No Exec

Enabled

Set Environment

Disabled

Review interactive database-client features carefully. A command-line client may allow file access, shell execution, or privileged database actions beyond the initial command.

Verify the Policy

After assigning the policy:

  1. Confirm that the Linux device is online in Swif.

  2. Confirm that the policy reports as installed.

  3. Verify the device’s sudoers syntax:

    sudo visudo -c
  4. List the current user’s effective sudo permissions:

    sudo -l

  5. If authorized, inspect another user’s permissions:

    sudo -l -U alice

  6. Run each intended command exactly as documented.

  7. Confirm that unrelated commands are denied.

  8. Test incorrect, missing, reordered, and additional arguments.

  9. Confirm that the required run-as user or group works.

  10. Verify whether the password prompt appears as configured.

  11. Test the effect of NOEXEC.

  12. Confirm that environment variables cannot be supplied when SETENV is disabled.

  13. Restart the device and repeat the verification.

  14. Review authentication and sudo logs.

visudo -c checks sudoers syntax and, depending on the implementation and invocation, can also validate included files, ownership, and permissions. See the Ubuntu visudo manual.

Keep an existing privileged session open during initial testing so the device can be recovered if a rule causes unexpected access problems.


Troubleshooting

The Policy Reports Installed but the User Has No Access

Check the following:

  • The rule is enabled.

  • The username or group name is correct.

  • The user is a current member of the configured group.

  • Directory-backed identities resolve on the device.

  • The host matches the configured host rule.

  • The executable path is absolute and correct.

  • The command arguments match exactly.

  • The requested run-as user and group are configured.

  • The executable still matches the configured SHA-256 digest.

  • A higher-priority Swif rule does not deny the command.

  • Another sudoers entry does not change the effective result.

Run:

id <username> 
sudo -l -U <username>
sudo visudo -c

A newly added group membership may require the user to sign out and sign back in before the session receives the updated group list.

The User Can Run More Commands Than Expected

  • Run sudo -l to inspect all effective permissions.

  • Review every policy assigned to the device and user.

  • Check /etc/sudoers and /etc/sudoers.d/.

  • Look for broad command entries or unrestricted arguments.

  • Check whether the user belongs to an administrative group such as sudo or wheel.

  • Review rules installed by configuration-management or identity products.

  • Check whether an allowed command can launch a shell, editor, interpreter, plugin, or secondary executable.

  • Confirm that the user cannot modify files consumed by the privileged command.

A narrowly written Swif rule cannot remove an independent permission granted elsewhere unless the effective sudoers configuration explicitly resolves the conflict that way.

A Deny Rule Does Not Block the Command

  • Confirm that the deny rule matches the same subject, host, run-as identity, path, and arguments.

  • Assign the restrictive rule a higher priority than the overlapping allow rule.

  • Check for another Swif policy granting the command.

  • Review local sudoers files for independent authorization.

  • Run sudo -l as the affected user.

  • Confirm that the user is not invoking a different executable path, symlink, or command form.

The Command Works Without the Configured Arguments

  • Confirm that Arguments were added to the command entry.

  • Verify the deployed rule after the device syncs.

  • Check for another rule that allows the same executable without argument restrictions.

  • Review all effective permissions with sudo -l.

  • Test the fully resolved executable path.

  • Check whether a wrapper, symlink, shell, or interpreter provides another execution path.

The Correct Command Is Denied

  • Compare the command with the configured argument list character by character.

  • Confirm argument order.

  • Check absolute paths included as arguments.

  • Confirm capitalization.

  • Check whether the user supplied extra options.

  • Verify the target run-as user and group.

  • Recalculate the SHA-256 digest.

  • Confirm that a software update did not replace the executable.

  • Review rule priorities.

SHA-256 Verification Fails After an Update

Software upgrades commonly replace executable files, producing a new digest.

  1. Verify that the update is approved.

  2. Calculate the new digest:

sha256sum /absolute/path/to/executable
  1. Update the rule with the new digest.

  2. Redeploy the policy.

  3. Verify the command and sudoers configuration again.

Do not remove digest verification permanently merely to bypass an unexplained mismatch. First confirm that the executable came from a trusted source.

Passwordless Execution Does Not Work

  • Confirm that Require Password is disabled.

  • Check for another matching rule with a higher priority.

  • Review local sudoers entries for a conflicting PASSWD tag.

  • Confirm the user is running the exact configured command.

  • Check the path, arguments, host, and run-as identity.

  • Run sudo -l to inspect the effective tag.

The User Is Not Prompted for a Password

A matching rule may use NOPASSWD, or the user may have a valid cached sudo authentication timestamp.

  • Confirm that Require Password is enabled.

  • Review all matching rules with sudo -l.

  • Clear the current user’s cached credentials before retesting:

sudo -k
  • Check the device’s sudo timestamp configuration.

  • Review local sudoers files for NOPASSWD.

No Exec Breaks the Command

The approved program may need to start a helper executable.

  • Review the program’s documented subprocesses.

  • Inspect the sudo or system logs.

  • Test with No Exec disabled on a nonproduction device.

  • Determine whether each helper can be separately authorized.

  • Disable NOEXEC only when required and after reviewing the increased risk.

Set Environment Is Required by an Application

Before enabling Set Environment:

  • Identify the exact variables the application requires.

  • Confirm how each variable changes privileged execution.

  • Check for library, interpreter, plugin, configuration, and path injection.

  • Restrict the command and arguments as narrowly as possible.

  • Test with an unprivileged user attempting to supply unexpected variables.

  • Document and periodically review the exception.

Host or Netgroup Matching Does Not Work

  • Confirm the current hostname with:

hostname 
hostname -f
  • Confirm the configured IP address with:

ip address
  • Verify DNS and identity-service connectivity.

  • Check whether the device has multiple hostnames or network interfaces.

  • Confirm netgroup resolution:

getent netgroup <netgroup-name>
  • Test whether the rule works temporarily with host type all.

  • Review the device’s effective sudo permissions.

Sudo Reports a Syntax Error

Run:

sudo visudo -c

If an error is reported:

  • Record the affected

Did this answer your question?