목. 7월 24th, 2025

What is sudo?

sudo (SuperUser DO) is a Linux command that lets authorized users run programs with administrative privileges. Instead of logging in as the all-powerful root user, you use sudo to temporarily elevate permissions for specific tasks. Think of it as shouting “I need admin rights!” only when necessary.

Linux terminal showing sudo command example


Why sudo Matters

  1. Security: Limits exposure of the root account
  2. Accountability: Logs all sudo commands (check /var/log/auth.log)
  3. Control: Admins decide who can do what
  4. Safety Net: Prevents accidental system-breaking commands

How to Use sudo (Basic Examples)

# Update package list (common first use)
sudo apt update

# Install software
sudo apt install firefox

# Edit protected config files
sudo nano /etc/hosts

# View logs requiring privileges
sudo tail -f /var/log/syslog

Graphic showing privilege escalation with sudo


The sudoers File: Controlled Power

Permissions are defined in /etc/sudoers (edit with sudo visudonever use a regular editor!). Example configuration:

# Allows user 'alex' to run ALL commands with sudo
alex   ALL=(ALL:ALL) ALL

# Allows 'backup-team' to run specific commands
%backup-team ALL=/usr/bin/rsync,/sbin/reboot

Pro Tips for Beginners

  1. Double-check commands before pressing Enter
  2. Use sudo !! to rerun last command with sudo
  3. Avoid sudo su – use sudo -i if needed
  4. Reset forgotten sudo password:
    sudo passwd username

When Things Go Wrong

Got this error?
username is not in the sudoers file. This incident will be reported.

Solution:

  1. Reboot into recovery mode
  2. Mount filesystem: mount -o remount,rw /
  3. Add user to sudo group:
    usermod -aG sudo username

Security Best Practices

✅ Use sudo instead of root login
✅ Grant minimal necessary permissions
✅ Regularly review /etc/sudoers
❌ Never share sudo passwords
❌ Avoid NOPASSWD in sudoers unless absolutely required

Infographic: sudo vs su comparison


Conclusion

Mastering sudo is your first step toward safe Linux administration. It balances security and functionality by giving temporary superpowers exactly when needed. Start with basic commands, respect its privileges, and you’ll navigate Linux administration with confidence!

> 🔍 Try it: Run sudo -l to see your allowed sudo commands!

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다