목. 7월 24th, 2025

Introduction to Sudo

Sudo (SuperUser DO) is a powerful command in Linux that allows authorized users to execute commands with superuser (root) privileges. It’s an essential tool for system administration while maintaining security.

Linux sudo command example

Why Sudo Matters

  1. Security: Prevents accidental system changes by regular users
  2. Accountability: Logs all sudo commands for auditing
  3. Controlled Access: Grants temporary root privileges without sharing the root password

Basic Sudo Commands

sudo apt update          # Update package lists
sudo systemctl restart apache2  # Restart a service
sudo nano /etc/hosts    # Edit protected files

The Sudoers File

The /etc/sudoers file controls who can use sudo and what commands they can run. Always edit it with:

sudo visudo

Editing sudoers file

Best Practices

  1. Use sudo instead of logging in as root
  2. Limit sudo access to trusted users
  3. Always double-check commands before running with sudo
  4. Use sudo -l to check your privileges

Common Mistakes to Avoid

  • Running graphical apps with sudo (use gksudo or pkexec instead)
  • Chaining dangerous commands with sudo (like sudo rm -rf /)
  • Granting unrestricted sudo access unnecessarily

Conclusion

Sudo is your gateway to powerful system administration while keeping your Linux system secure. Start with basic commands and gradually explore more advanced sudo configurations as you gain experience.

답글 남기기

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