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 do you switch users in CentOS?

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:

  1. Open a terminal window in CentOS.
  2. Type the following command:
su - username

Replace 'username' with the username of the user account you want to switch to.

  1. Press 'Enter' and then enter the password for the user account when prompted.
  2. You will now be switched to the specified user account.
  3. 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':

  1. Open a terminal window in CentOS.
  2. Type the following command to switch to the root user:
sudo su -
  1. Enter the password for the current user when prompted.
  2. You will now be switched to the root user account.
  3. 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.

  1. Enter the password for the current user when prompted.
  2. You will now be switched to the specified user account.
  3. 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:

  1. Open a terminal window in CentOS.
  2. Type the following command:
login
  1. Enter the username and password of the user account you want to switch to when prompted.
  2. You will now be logged in as the specified user account.
  3. 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:

  1. Open a terminal window in CentOS.
  2. Type the following command:
su -s /bin/bash username

Replace 'username' with the username of the user account you want to switch to.

  1. Enter the password for the user account when prompted.
  2. You will now be switched to the specified user account with the '/bin/bash' shell.
  3. 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?

like

dislike

love

funny

angry

sad

wow