Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

Discussing that is beyond the scope of this chapter, but for the sake of
argument, for the scenario and details in this section, assume that you are
operating in one of those special cases and that a root account has been
enabled.


What if you have access to an enabled root account as a super user but are
logged on as a regular user because you are performing nonadministrative
tasks, and you find that you need to do something that only the super user can
do? The su command is available for this purpose.


NOTE
A popular misconception is that the su command is short for super user; it
really just means substitute user. An important but often overlooked
distinction is that between su and su -. In the former instance, you
become that user but keep your own environmental variables (such as
paths). In the latter, you inherit the environment of that user. This is most
noticeable when you use su to become the super user, root. Without
appending the -, you do not inherit the path variable that includes /bin or
/sbin, so you must always enter the full path to those commands when
you just su to root.
Don’t forget that on a standard Ubuntu system, the first created user is
classed as root, whereas the true root account is disabled. To enable the root
account, you enter the command sudo passwd at the command line and
enter your password and a new root password. After this has been
completed, you can su to root. We suggest you read the information at
https://help.ubuntu.com/community/RootSudo before doing so to ensure
that you understand the reason the root account is not enabled by default.

Because almost all Linux file system security revolves around file
permissions, it can be useful to occasionally become a different user with
permission to access files belonging to other users or groups or to access
special files (such as the communications port /dev /ttyS0 when using a
modem or the sound device /dev/audio when playing a game). You can
use the su command to temporarily switch to another user identity and then
switch back.


The su command spawns a new shell, changing both the UID and GID of the
existing user and automatically changing the environmental variables
associated with that user, known as inheriting the environment. For more
information about environment variables, see Chapter 5, “Productivity
Applications.”

Free download pdf