In this part of RHCSA exam preparation you will learn how to login to your RHEL system and how to switch between regular and root user.

In this tutorial you will learn:
  • How to login as a regular user or root
  • How to switch user in multiuser target
typical multi-user login screen on GNU/Linux as in this case RHEL 8
A typical multi-user login screen on GNU/Linux as in this case RHEL 8

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Red Hat Enterprise Linux 8
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

How to verify multi-user target

First, verify that your system is running in the multi-user level of operation.

  1. To do so execute the following systemctl command.
    $ systemctl get-default
    

  2. SUBSCRIBE TO NEWSLETTER
    Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


  3. In case your system does not currently boot into multi-user runlevel by default execute the following command to change the default boot target.
    # systemctl set-default multi-user
    
  4. Reboot your system
    # reboot
    

Log in and switch users

By now you should have a login prompt in front of you running the multi-user runlevel.

  1. Login into the system as a regular user. During the RHEL installation you have created at least one user so use the user credentials and log in. After successful login your should see a prompt similar to the one below:
    [linuxconfig@rhcsa ~]$
    
    The prefix before the actual $ sign on your prompt will be different. However, by default it displays a user name of the user which is currently logged in and the RHEL system's hostname.

    The most important part to note here, however, is the actual $ sign. There are only two possible characters which might be displayed at the end of your shell prompt and they are the $ and #.

    The $ sign indicates that you are logged in as a non-privileged regular user and will not be able to perform any administrative tasks. On the other hand the # denotes that you have gained a root administrative access allowing you to perform any administrative and non-administrative tasks.
    DID YOU KNOW?
    That it is a good Linux system administrator practice to perform any tasks which do not require privileged administrative access as a regular user. It is possible to perform any given task as a administrative root user, however, your risk to inadvertently damage your system, or delete data as a result of mistake or accident. It is highly recommended to gain administrative access only in case that the task ahead requires it!


  2. Gain root access by using the su command and using - as an argument and provide the appropriate root password. Follow this tutorial in case you need to reset your root password:
    [linuxconfig@rhcsa ~]$ su -
    
  3. Confirm that your have gained root access by execution of the whoami command. Seeing the # sign at the end of your shell prompt is also a good indication that your have gained a privileged system access.
    
    [root@rhcsa ~]# whoami 
    root
    [root@rhcsa ~]#
    
  4. Login back as a regular user. Since we have already logged in as a regular user all we have to the is to exit the root shell session gained in the previous step by executing the exit command or pressing the CTRL+d key combination:
    [root@rhcsa ~]# whoami 
    root
    [root@rhcsa ~]# exit
    logout
    [linuxconfig@rhcsa ~]$ whoami 
    linuxconfig
    [linuxconfig@rhcsa ~]$
    
    Yet, another alternative exists and that is to create another regular user session by using the su - command with an argument of the user we wish to login as. Example:
    [root@rhcsa ~]# whoami 
    root
    [root@rhcsa ~]# su - linuxconfig
    [linuxconfig@rhcsa ~]$ whoami 
    linuxconfig
    [linuxconfig@rhcsa ~]$
    


    NOTE
    When using the su command from a root privileged shell the user does not need to enter the appropriate regular user password. However, accessing root shell from a regular user shell session by using the su command, the user is required to enter the appropriate root or regular user password.

Exercises

  1. Change your default boot target unit to graphical.target. Is there any difference when switching users from a terminal command line in comparison to the multi-user runlevel?
  2. What is the difference between execution of the following to commands?
    $ su linuxconfig
    
    AND
    $ su - linuxconfig
    
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.