How to configure PHP parameters on Linux Serv
PHP a widely used server-side scripting language plays ...
User management is an important aspect of maintaining an efficient and secure Linux server. One essential tool for managing user sessions and permissions in Linux is sudo. sudo stands for “superuser do” and allows authorized users to execute commands as another user, usually the root or superuser. To switch users in Linux, use the command “su”, while replacing the username of the account you want to switch.
In this post, we will discuss how to manage user sessions in Linux using sudo, including configuring and customizing sudo for specific needs. If you are new to Linux this post is helpful to you regarding how you can create and switch users in Linux using the command line.
Sudo is a command that allows users to run programs with the privileges of another user, by default, the superuser. This is useful for tasks that require administrative privileges, such as installing software, deleting files, and managing user accounts.
How does sudo work?
It is important for beginners to understand how sudo works When you run a sudo command:
To manage user sessions with sudo, you first need to check that sudo is installed on your Linux system. Most distributions installed sudo by default, but you can install it if it’s not present. For example, on Debian-based like the Ubuntu servers, you can type the following command:
apt install sudo
To install in Fedora or CentOS system, you can type the following command:
yum install sudo
After installing you can confirm by typing the following command.
sudo -h
As the picture shows below the usage of sudo:
Sudo will read the /etc/sudoers file and check whether the user has sudo access permission. When you use sudo for the first time in a session, you will be requested for the user password, and the command will be run as root. You can also modify the configuration file by using the command:
sudo visudo
This will open the /etc/sudoers file. Add the following code to add a user with full sudo privileges:
[username] ALL=(ALL:ALL) ALL
We use the su command combined with sudo. By combining the sudo and su commands, you can switch to a different user session with elevated privileges.
Using the sudo su command
The su
command (short for substitute or switch user) allows you to run commands with another user’s privileges, by default the root user. The sudo
command (short for the superuser do) allows you to run commands as another user, by default the root user.
To change your user session using sudo su, follow these steps:
sudo su username
Replace the username with the name of the user you want to switch to. For example, to switch to the root user, you would type:
sudo su - root
To log out another user, you can use the following command:
sudo pkill -u username
This will terminate all of the processes running under the specified user account. The user will then be logged out.
To kill a specific process belonging to another user, you can use the following command:
sudo killall process_name
This will terminate all of the processes with the specified name.
To change the password of another user, you can use the following command:
sudo passwd username
This will prompt you to enter the new password for the specified user account.
Be careful when using sudo su to switch to a different user session. With elevated privileges, you can make changes to the system that could potentially cause damage. Only switch to a different user session if you are sure that you need to, and be careful about the commands that you run.
Here are some best practices for using sudo:
sudo can be used to manage user sessions and run commands with elevated privileges. To understand how sudo works and how to configure it, you can use sudo to improve the security and efficiency of your Linux system. It is important to use sudo wisely and to follow the best practices outlined above to keep your system secure.
Sudo is a command-line utility that allows users to run programs with the security privileges of another user, You can practice sudo commands on our Ultahost Linux VPS. Ultahost comes with cheap VPS hosting solutions to provide flexibility and control.