Log in as a nonroot user; this is an ordinary system user without administrative privileges. The terminal console will display the time of our last login, and then we will find ourselves at the shell prompt, indicated by the dollar sign.
To logout, we enter the command logout. We can then log in again as root, the administrative superuser. The terminal console will display the last time the root superuser logged in, and then display the shell prompt. Note that since we are logged in as root, the last character of the shell prompt is a hash mark instead of a dollar sign.
Again, we log out using the logout command.
The next command we will learn is the substitute user command; this command follows the form su and then the same of the user we wish to be.
To log in as root, we simply issue the su command without adding a username to the end. Typically, it’s best to add a hyphen to the end of the su command when switching to root, and between the su command and the username when we are switching to a different user. By adding a hyphen, we start the user’s session as a login shell. Note that when logging in as a regular user from root it is not necessary to enter a password.
The Bourne-Again shell, known as the bash shell, is an improved version of the original Unix shell developed in the 1970s. The bash shell is usually the default, and it is the shell we have been using so far. We enter commands at the shell’s prompt. As we have seen, the standard user prompt begins with a dollar sign, and the root superuser’s shell prompt begins with a hashtag.
Behind the dollar sign or hastag symbol, we can see that the bash shell displays additional information. By default, we are shown our username, followed by the @ symbol and the hostname of the system we are on. Additionally, we can verify who we are by entering the whoami command.
Each user has a home directory, which is where their personal files are stored. By default, when we open a terminal window as a user we being in our home directory. The home directory for all ordinary users are by default stored together in the /home directory.
To find out what directory we are in, we can use the print working directory command, pwd. We can use the pwd command to find where we are in the filesystem at any given time.
Note in the example above that when we logged in as root and entered the pwd command the system told us that we weren’t in the /home directory at all. The home directory of the root user is intentionally kept spearate from the home directories of regular users.
As an example, if we enter the su command to switch to root, and we do not place a hyphen after su, we will find we are still in the home directory of the original user.
When we switched users, we did not start a new login shell, since we ommitted the hyphen. If we began issuing commands right away as the root superuser, we could inadvertently alter the files and directories of a regular user. For this reason, it is generally a good idea to issue the command su – rather than su.