Skip to content

Linux commands: sudo

A quick guide to the `sudo` command, used to run a command as another user

sudo is commonly used to run a command as root.

You must be enabled to use sudo, and once you do, you can run commands as root by entering your user’s password (not the root user password).

The permissions are highly configurable, which is great especially in a multi-user server environment, and some users can be granted access to running specific commands through sudo.

For example you can edit a system configuration file:

sudo nano /etc/hosts

which would otherwise fail to save since you don’t have the permissions for it.

You can run sudo -i to start a shell as root:

You can use sudo to run commands as any user. root is the default, but use the -u option to specify another user:

sudo -u flavio ls /Users/flavio

The sudo command works on Linux, macOS, WSL, and anywhere you have a UNIX environment


→ Get my Linux Command Line Handbook

→ I wrote 17 books to help you become a better developer:

  • C Handbook
  • Command Line Handbook
  • CSS Handbook
  • Express Handbook
  • Git Cheat Sheet
  • Go Handbook
  • HTML Handbook
  • JS Handbook
  • Laravel Handbook
  • Next.js Handbook
  • Node.js Handbook
  • PHP Handbook
  • Python Handbook
  • React Handbook
  • SQL Handbook
  • Svelte Handbook
  • Swift Handbook
...download them all now!

Also, JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025

Bootcamp 2025

Join the waiting list