Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

The sudo Command


You will find as you work through this book that Ubuntu relies on the sudo
command while you work at the command line. This command is used in
front of other commands to tell Ubuntu that you want to run the specified
command with super user powers. This sounds really special, and it actually
is. When you work using the sudo command, you can make wide-ranging
changes to your system that affect the way it runs. Be extra careful when
running any command prefixed with sudo, however; a wrong option or an
incorrect command can have devastating consequences.


The use of sudo is straightforward. All you have to do is enter it like this:


Click here to view code image
matthew@seymour:~$ sudo command commandoptions


Just replace the word command with the command you want to run and
commandoptions with any options. For example, the following command
opens your xorg.conf file in vi and enables you to make any changes as
the super user before being able to save it:


Click here to view code image
matthew@seymour:~$ sudo vi /etc/X11/xorg.conf


Whenever you execute a command using sudo, you are prompted for your
password. This is the same password that you use to log in to Ubuntu, so it is
important that you remember it.


Sometimes, however, you might want to work with a classic root prompt
instead of having to type sudo in front of every command (if you have to
work with lots of commands at the command line that require super user
access, for example). sudo enables you to do this by using the sudo -i
command. Again, you are prompted for your password, which you should
enter, after which Ubuntu gives you the standard root prompt, as follows:


matthew@seymour:~#

From here, you can execute any command without having to keep entering
sudo.


WARNING
Working from the root prompt can be really dangerous unless you know
what you are doing. Until you are experienced, we recommend that you
stick to using sudo, which is covered in more detail in Chapter 10,
“Command-Line Beginner’s Class.”
Free download pdf