Skip to content

Linux sudo Guide

Mattscreative edited this page Dec 5, 2025 · 2 revisions

Linux sudo Guide

Complete beginner-friendly guide to sudo on Linux, covering Arch Linux, CachyOS, and other distributions including sudo configuration, user permissions, and security settings.


Table of Contents

  1. Understanding sudo
  2. sudo Installation
  3. Basic sudo Usage
  4. sudo Configuration
  5. Troubleshooting

Understanding sudo

What is sudo?

sudo allows users to run commands as another user (usually root).

Benefits:

  • Security: No need for root password
  • Audit trail: Logs all sudo commands
  • Granular control: Fine-grained permissions
  • Safety: Prevents accidental damage

Why use sudo:

  • Best practice: Safer than su
  • Accountability: Track who did what
  • Flexibility: Configure per-user permissions

sudo Installation

Install sudo

Arch/CachyOS:

# Install sudo
sudo pacman -S sudo

# Usually pre-installed

Debian/Ubuntu:

sudo apt install sudo

Fedora:

sudo dnf install sudo

Verify Installation

Check sudo:

# Check version
sudo --version

# Check if user in sudoers
sudo -l

Basic sudo Usage

Run Command as Root

Basic usage:

# Run command as root
sudo command

# Example
sudo pacman -S package-name

Switch to Root

Become root:

# Switch to root shell
sudo su

# Or
sudo -i

Run as Another User

Different user:

# Run as specific user
sudo -u username command

# Example
sudo -u www-data ls /var/www

sudo Configuration

Edit sudoers

Configure sudo:

# Edit sudoers (safe)
sudo visudo

# Never edit directly with regular editor

Basic Configuration

Allow user sudo:

# In visudo
username ALL=(ALL) ALL

# Or group
%wheel ALL=(ALL) ALL

Advanced Configuration

Granular permissions:

# Allow specific command
username ALL=(ALL) /usr/bin/pacman

# No password
username ALL=(ALL) NOPASSWD: ALL

# Specific host
username hostname=(ALL) ALL

Troubleshooting

Permission Denied

Check configuration:

# Check sudo access
sudo -l

# Verify user in wheel group
groups

# Add to wheel group
sudo usermod -aG wheel username

sudo Errors

Check logs:

# Check sudo logs
sudo journalctl -u sudo

# Or
cat /var/log/auth.log

Summary

This guide covered sudo installation, configuration, and usage for Arch Linux, CachyOS, and other distributions.


Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally