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→