Difference Between su and sudo in Linux

In the Linux operating system, both su and sudo are critical command-line utilities used to execute tasks with elevated or administrative privileges. While they achieve similar administrative results, they operate on fundamentally different security models. This article explains what each command does, compares how they authenticate users and manage access, highlights their security and logging implications, and outlines when to use each in daily administration.


What is su?

The su command stands for "substitute user" or "switch user." It allows you to switch from your current user account to another account in a new shell session. By default, running su without any arguments attempts to switch directly to the root (superuser) account.

What is sudo?

The sudo command stands for "superuser do." It is designed to run a single command with root privileges (or the privileges of another specified user) without switching to a persistent root shell.


Key Differences

1. Password Management and Security

2. Scope of Access

3. Accountability and Logging


Comparison Table

Feature su sudo
Meaning Substitute User / Switch User Superuser Do
Password Required Target user's password (root) Current user's password
Scope Persistent shell session Single command execution
Granular Control No (all-or-nothing access) Yes (configured via /etc/sudoers)
Command Auditing Poor (only session start is logged) High (every executed command is logged)
Default in Modern Linux Often disabled/root locked (e.g., Ubuntu) Standard method for admin tasks

Best Practices: Which Should You Use?

Modern Linux distributions (including Ubuntu, Debian, Fedora, and CentOS/RHEL) recommend using sudo for almost all administrative work. It enforces better security hygiene, prevents accidental system-wide changes, preserves an audit trail, and eliminates the need to distribute the root password.

The su command is generally reserved for environments where a dedicated, prolonged session as another user is explicitly required, or for legacy systems where sudo is not configured.