Click on each book below to review & buy on Amazon.
As an Amazon Associate, I earn from qualifying purchases.
RHCSA - Understand and Use Essential Tools: Log in & Switch Users in Multiuser Targets
This guide covers essential Linux system administration topics for the RHCSA certification. It focuses on multi-user targets in systemd, different methods for user login (graphical, text-based, SSH), and user switching techniques using su
and sudo
commands. These topics are essential for understanding and managing multi-user environments in Linux.
Multi-User Targets
Linux systems utilizing systemd, incorporate a system state and management structure known as 'targets'. A target in the context of systemd is essentially a group of systemd units, which can include services, sockets, device mounts, and other components. These units are collectively organized to define and achieve specific system states for various purposes.
One of the most significant and commonly employed targets within the Linux environment is the multi-user target. This target is tailored for scenarios where a system needs to support multiple users, typically in settings that do not require a graphical user interface (GUI) but do require network capabilities.
The multi-user target is distinguished by its non-graphical nature. It primarily provides a command-line interface (CLI), which is an ideal setup for servers or headless machines where a GUI might be unnecessary or even a hindrance due to resource constraints. Users interact with the system in this target through terminal sessions, which can be accessed either directly on the machine or remotely via network protocols like SSH.
A key characteristic of the multi-user target is its readiness for network interactions. This target ensures that the system is prepared to handle various network services. These services can range from SSH for remote access to web servers for hosting websites, and even include file sharing services. The network-enabled state of the multi-user target makes it an excellent choice for running server applications that necessitate constant network connectivity.
As the name implies, the multi-user target accommodates simultaneous use by several users. This support is not limited to local access; remote logins are facilitated, assuming necessary services such as SSH are enabled and properly configured. This functionality is important in shared server environments, educational settings, and businesses where multiple individuals need to access the system concurrently.
In the multi-user target, common system services are active and operational. These services encompass system logging (like syslog or journald), cron services for scheduling tasks, as well as print and email services. The selection of active services aims to provide a comprehensive environment suitable for a variety of tasks typical in a multi-user context.
The multi-user target finds extensive use in server environments where a GUI is unnecessary. It's also prevalent in workstations dedicated to development, scripting, or remote management. The target's versatility and its non-reliance on a GUI make it a preferred choice for backend systems, data servers, and application servers.
Log in as a User
There are 3 mains ways for logging in as a user in a multiuser environment, which are:
- Using the Graphical environment
- Using the text based terminal console
- Connecting remotely through SSH
You would have already logged in using the graphical environment and remotely via SSH when following along with this course. Therefore the text based console will be demonstrated here.
On server1
you can switch to a text based terminal console by using the chvt
command or by using Ctrl+Left Alt+F3.
Info
The Ctrl is optional depending on what hypervisor or bare metal setup you are running on. Additionally, F3 can be replaced up to F12, however for both the chvt
command and the key shortcuts, most installations will have 3-6 available by default.
The chvt
command stands for "change virtual terminal", and is a simple yet effective tool used to switch between different virtual terminals. These virtual terminals are text-based consoles that you can access independently of your graphical desktop environment. By executing chvt
followed by a terminal number, like chvt 2
, you can switch to the second virtual terminal, allowing you to manage multiple sessions from a single physical machine. It's particularly useful in situations where you need to perform tasks outside of the graphical interface or when automating processes across different terminals.
Exercise: Using the chvt
command to change to terminal /dev/tty3
sudo chvt 3
Enter your password to elevate your privileges.
[sudo] password for user1:
You are now presented with the text based terminal console where you first enter the username you wish to login as, and then enter that users password.
Red Hat Enterprise Linux 9.2 (Plow)
Kernel 5.14.0-284.18.1.el9_2.x86_64 on an x86_64
Activate the web console with: systemctl enable --now cockpit.socket
server1 login: root
Password:
Last login: Sun Jun 25 14:43:42 on tty3
To return to the graphical environment, run:
sudo chvt 2
Switching Users
The su
command can be used to switch users. When run with the -
, -l
or --login
flags, the shell will start as a login shell (similar to a real login). When run without those arguments, you will retain the majority of the environment settings of the current user.
In this exercise you will switch to the root
user with a login environment:
Exercise: Switch to root
user with a login environment:
When switching to root
you can omit the username, as by default, su -
will perform su - root
.
su - root
pwd
Enter the root
password when prompted and ensure you have simulated a login environment by running pwd
. The output should show /root
.
In this exercise you will switch to the root
user with a non-login environment:
Exercise: Switch to root
user with a non-login environment:
su root
pwd
Enter the root
password when prompted and ensure you have a non-login environment by running pwd
. The output should show that you did not enter the /root
directory, for example /home/user1
would return if that was where you ran the su
command from.
Unlike the su
command where you can switch to any user, you can use the sudo
command with the -i
or --login
flags to login as the root
user, which you will try out in the below exercise:
Exercise: Login as the root
user using sudo
.
When using sudo
it will prompt for the password of the current user, in this example, user1
:
sudo -i
Or:
sudo --login
Conclusion
This guide provides a thorough understanding of managing multi-user environments in Linux, focusing on systemd's multi-user targets. It covers various user login methods, including graphical interfaces & text-based consoles. Additionally, it delves into user-switching techniques using su
and sudo
commands.
Support DTV Linux
Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.
NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.