Operations 4 min read

How to Block Regular Users from Using the su Command on Linux

This guide explains why the su command is available to all users by default, then shows how to back up the sudoers file, edit it with visudo, define a command alias to disable /usr/bin/su, and apply the restriction to individual users or entire groups, complete with verification steps.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Block Regular Users from Using the su Command on Linux

The su command lets a user run commands as another user or group, often used to switch to the root account. By default, every Linux user can invoke su, which may be undesirable in a multi‑user environment.

Backup the sudoers file

Before making any changes, create a copy of /etc/sudoers to preserve the original configuration:

sudo cp -p /etc/sudoers /etc/sudoers.back

Edit sudoers safely with visudo

Open the sudoers file using visudo, which checks syntax before saving:

sudo visudo

Define a command alias that disables su

Locate the ## Command Aliases section and add the following line:

Cmnd_Alias DISABLE_SU = /usr/bin/su

Restrict a specific user

At the end of the file, add a rule for the user (replace bob with the target username) that denies the alias while keeping other sudo privileges: bob ALL=(ALL) NOPASSWD: ALL, !DISABLE_SU Save and exit. When bob attempts to run su - user01, the system will respond with an error such as:

Sorry, user bob is not allowed to execute '/bin/su - user01' as root on localhost.localdomain.

Disable su for an entire group

To block all members of a group (e.g., wheel), add a similar rule using the group name: %wheel ALL=(ALL) ALL, !DISABLE_SU After saving, any user belonging to the wheel group will be prevented from using su.

Verification

Test the restriction by switching to the affected user and running the su command. The expected error confirms that the configuration works as intended.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

access controlLinuxsudoerssu command
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.