QA
Beginner LevelLinux Commands & SysAdmin

What is the difference between sudo and su (su -)?

❓ Interview Prompt: Compare sudo (execute single command with root rights) vs su (switch user) vs su - (switch user with login environment).

1. 'sudo <command>':

Executes a single command with root (or target user) privileges, authenticating with the current user's password. Logged in '/var/log/auth.log' for auditability!

2. 'su <user>':

Switches current shell to target user, keeping current environment variables.

3. 'su - <user>' / 'su -':

Switches to target user (default root) and loads their full login environment (HOME, PATH, shell config). Requires target user's password.

Code Implementation Example

bash
# Execute single administrative command via sudo
sudo apt update

# Switch to root user with full login environment
sudo su -
# OR
su -
💡Executing administrative tasks using sudo vs switching to root via su -.
🎯 Interview Key Takeaway

Prefer sudo over direct root logins to maintain audit trail logging and principle of least privilege.

#sudo#su#Privileges#Security#Beginner
Back to all Linux Commands & SysAdmin Questions→

More Linux Commands & SysAdmin Interview Questions

Beginner LevelLinux Commands & SysAdmin

How do Linux File Permissions (chmod, chown, chgrp) work in Octal and Symbolic notation?

Beginner LevelLinux Commands & SysAdmin

What is the Linux Filesystem Hierarchy Standard (/bin, /etc, /var, /usr, /opt, /tmp)?

Beginner LevelLinux Commands & SysAdmin

What are File Descriptors (0=stdin, 1=stdout, 2=stderr) and Redirection (>, >>, 2>&1)?