The sudo
command in Linux allows users to run commands with administrative (root) privileges. It temporarily elevates privileges, making it safer than directly logging in as root.
Syntax:
bash
sudo <command>
Examples:
- Update system packages:
bash
sudo apt update
- Edit a file with administrative rights:
bash
sudo nano /etc/hostname
- Restart a service:
bash
sudo systemctl restart nginx
- Switch to root user:
bash
sudo su
- View system logs:
bash
sudo tail /var/log/syslog
Use sudo
responsibly to prevent accidental system changes.