Skip to content
Linux su vs sudo vs sudo su vs sudo -i: Key Differences Explained
Operations 4 min read

Linux su vs sudo vs sudo su vs sudo -i: Key Differences Explained

This article explains the differences between Linux su, sudo, sudo su, and sudo -i commands, covering password requirements, environment variable handling, shell behavior, and practical usage scenarios for switching user privileges.

Linux Tech Enthusiast
Linux Tech Enthusiast
Linux Tech Enthusiast

sudo vs su: Core Differences

Password requirement: sudo prompts for the current user's password, while su requires the target user's password (typically root).

Scope of privilege elevation: sudo runs a single command with elevated privileges and then returns to the original shell. su starts a new interactive shell as the target user, allowing multiple commands until the user explicitly exits.

Reference: Linux 命令 su 和 sudo 的区别 (http://mp.weixin.qq.com/s?__biz=MzAwMjg1NjY3Nw==&mid=2247518621&idx=2&sn=dec71be1e4b7dbf88911bdf042b66434&chksm=9ac6ca17adb14301b8ea02d69d0dd61c90ede6733c8e1b7463191ff42c23273bf6c60c00b45b&scene=21#wechat_redirect)

Switching User Identity with su

By default, su only changes the user identity; environment variables remain those of the original user.

Using su - (or su - username) switches both identity and environment variables to the target user's environment. The hyphen cannot be omitted if the new environment is required for certain operations.

Examples: su root — after entering the root password, the current working directory stays unchanged. su - root — after entering the root password, the working directory changes to /root.

sudo Command Variants and Behavior

The following forms are functionally equivalent: sudo -i root, sudo - root, sudo -i, sudo -, sudo root. All prompt for the current user's password and require the user to be listed in /etc/sudoers.

sudo vs su summary: sudo: Temporarily elevates to superuser (usually root) for a single command. Uses the current user's password. Ubuntu defaults to a 15‑minute timeout before re‑prompting. su: Switches to the specified user (defaults to root). Uses the target user's password. No automatic timeout; the session persists until exit or logout.

sudo -i starts an interactive root shell without repeated password prompts. The prompt changes from $ to #. Exit with exit or logout. The invoking user must be in sudoers.

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.

Linuxshellenvironment variablessudorootsusudo -isudo su
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.