sudo command

sudo command allows you to run a Unix command as a different user. Using /etc/sudoers file to confirm what privileges are available to you, this command effectively elevates your access rights, thus allowing you to run commands and access files which would otherwise be not available to you.

Simplest usage is: sudo followed by the command you want to run as root. You’ll be asked for your password (not root’s password!) and if you are allowed to use sudo, it will work like this:

[email protected]:~ $ sudo whoami

As you can see from the output, whoami command reports that it’s run by the user root (because sudo elevates your privileges).

There’s usually no need to type password for subsequent sudo commands in the same login session. So if you’re asked sudo once, you can execute multiple sudo commands in the same session and it won’t ask for your password again:

[email protected]:~ $ sudo whoami
[email protected]:~ $ sudo id
uid=0(root) gid=0(wheel) groups=0(wheel),1(daemon),2(kmem),3(sys),4(tty),5(operator),8(procview),9(procmod),12(everyone),20(staff),29(certusers),61(localaccounts),80(admin),701(,33(_appstore),98(_lpadmin),100(_lpoperator),204(_developer),250(_analyticsusers),395(,398(,399(

See Also

  • sudo tutorial
  • visudo command
  • editing /etc/sudoers file with visudo
  • using sudo
  • visudo tutorial
  • using visudo

Keep Learning

Follow me on Facebook, Twitter or Telegram:
I learn with Educative: Educative I'm also a fan of SetApp for macOS: SetApp for macOS
IT Consultancy
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!
Recent Articles
31 Jan 2023

Homelab: MacBook Pro M2

17 Nov 2022

Video: awk delimiters

25 Oct 2022

macOS Ventura 13.0

Recent Tweets