How to Switch or Change Users in a Linux Shell

Guide to how to change users in a Linux – System, user, and root are the three types of accounts in Linux. By providing his/her username and password, a user signs into his/her Linux user account. When system processes, such as mail, start, they also log in to Linux. The root account is a special user account that has full access to the system and may conduct any activity. You may change users in Linux with the “su” command, also known as “substitute user”, “super user” or “switch user”. As long as you know the password to another account and the account allows user logins.

The su Command for Change Users in a Linux

Type “su -” followed by a space and the target user’s username to switch to a different user and start a session as though the other user had logged in from a command prompt. When asked, provide the password of the target user. If you leave off the hyphen, you’ll log into the other user’s account using your environment variables, which may provide different results than what the user would see when signing in. To log out of the account and return to the previous user session, type “exit” and hit “Enter.”

$ su <option> <user>

The Root Account

On most Linux systems, only a few experienced and trustworthy users are allows to log in as the root user. Because the root user has the ability to read, change, and remove any file or configuration on the server. Many Linux systems require that a root session be begun from another user session using the “su” command to prevent a hacker from signing in as “root”. When you type “su -” and click “Enter” without a username. The system believes you want to log in as the root user and prompts you for the root user password.

Security Risks With su

The su command requires actions that are in direct opposition to most network security principles and practices. In Linux, for example, if you use the su command to change users, the other user must disclose his password. Switching to the root user requires system administrators to share a single root password. While this configuration may not be a problem for a three-user hobbyist network. It is an unacceptable security risk in many commercial Linux networks, and many network security rules demand that the command be deactivated.

The sudo Utility for Change Users in a Linux

The “sudo” utility is a popular and secure alternative to the su command. Users who can switch to other accounts, such as the root account, are lists in a sudo configuration file. When a user types “sudo” before a command, he is prompted for his password, and the system only runs that command as the root user. There’s no chance of losing the root password or forgetting to log out of the root account while using sudo.

$ sudo -u <user> <command>

That’s all for this article if you have any confusion contact us through our website or email us at [email protected] or by using LinkedIn

Suggested Articles:

  1. How to Install LAMP on Ubuntu 18.04

Leave a Comment