How do you switch users in CentOS?
Learn how to easily switch users in CentOS using the su command. Follow our step-by-step guide to seamlessly navigate between different user accounts.
How to Switch Users in CentOS
Switching users in CentOS is a common task that allows different users to work on the same system without interfering with each other's work. In this guide, we will explore various methods to switch users in CentOS.
Method 1: Using the 'su' Command
The 'su' (substitute user) command in CentOS allows you to switch to another user account. Here's how you can use it:
- Open a terminal window in CentOS.
- Type the following command:
su - username
Replace 'username' with the username of the user account you want to switch to.
- Press 'Enter' and then enter the password for the user account when prompted.
- You will now be switched to the specified user account.
- To return to your original user account, type:
exit
Method 2: Using the 'sudo' Command
The 'sudo' command in CentOS allows you to perform administrative tasks as another user, typically the root user. Here's how you can switch users using 'sudo':
- Open a terminal window in CentOS.
- Type the following command to switch to the root user:
sudo su -
- Enter the password for the current user when prompted.
- You will now be switched to the root user account.
- To switch to another user account using 'sudo', type:
sudo su - username
Replace 'username' with the username of the user account you want to switch to.
- Enter the password for the current user when prompted.
- You will now be switched to the specified user account.
- To return to your original user account, type:
exit
Method 3: Using the 'login' Command
The 'login' command in CentOS allows you to log in as a different user without logging out of the current session. Here's how you can use it:
- Open a terminal window in CentOS.
- Type the following command:
login
- Enter the username and password of the user account you want to switch to when prompted.
- You will now be logged in as the specified user account.
- To return to your original user account, you can simply log out of the current session.
Method 4: Using the 'su' Command with Different Shell
You can also switch users in CentOS using the 'su' command with a different shell. This can be useful if you want to switch to a user account with a specific shell configuration. Here's how you can do it:
- Open a terminal window in CentOS.
- Type the following command:
su -s /bin/bash username
Replace 'username' with the username of the user account you want to switch to.
- Enter the password for the user account when prompted.
- You will now be switched to the specified user account with the '/bin/bash' shell.
- To return to your original user account, type:
exit
Method 5: Using the 'ssh' Command
If you are working on a remote CentOS server, you can switch users using the 'ssh' command.
What's Your Reaction?