sudo vs su — What's the Difference in Linux?

sudo runs a single command with elevated (root) privileges; su switches your entire shell session to another user, typically root.

Published October 2, 2026

sudo runs a single command with another user's privileges (usually root) using your own password, with logging; su switches to another user's full shell using that user's password. sudo is preferred.

How it works

sudo grants fine-grained, audited, temporary privileges configured in /etc/sudoers. su gives a persistent root shell, which is riskier.

sudo -i or sudo su - opens a root shell when needed.

Try it

sudo systemctl restart nginx
[sudo] password for ada:
su - postgres

Practical examples

Run one command as root

sudo apt update

Run as another user

sudo -u postgres psql

Root shell

sudo -i

Edit sudoers safely

sudo visudo

Common mistakes

  • Running everything as root.
  • Editing /etc/sudoers directly instead of visudo.
  • Using sudo with shell redirection (sudo echo x > file fails; use tee).

Key takeaways

  • sudo = per-command, audited.
  • su = switch user shell.
  • Prefer sudo.

FAQ

Why does sudo echo > file fail?

The redirection runs as your user; use sudo tee.

Disable password for sudo?

Possible via sudoers NOPASSWD, but risky.

More Linux articles