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
Password:
root

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
Password:
root
[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(com.apple.sharepoint.group.1),33(_appstore),98(_lpadmin),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh)

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:
Recommended
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
09 Mar 2022

Linux Mint as a Desktop OS

14 Oct 2021

Ubuntu 21.10 Impish Indri

15 Aug 2021

Python 3.10 Released

Recent Tweets