Sign In
Sign In

How to Switch Users in Linux

How to Switch Users in Linux
Hostman Team
Technical writer
Linux
11.09.2024
Reading time: 5 min

Computers store vast amounts of information, ranging from documents and photos to work projects and sensitive data. Now, imagine several people using the same computer. Each of them needs their own space, settings, and files. This raises the question: Is it possible to quickly switch users in Linux so everyone can work with their own data without disturbing others?

Linux distributions offer the ability to change users instantly. In this guide, we'll look at several ways to do this, ensuring that all users on your system have their own workspace.

Switching Users in Linux

Switching user accounts in Linux can be useful at any time. This is not only important for system security (access control) but also for improving work efficiency. Below are some scenarios where you might need to switch users in Linux:

  1. Shared system use: When multiple users share one computer, switching users allows each person to maintain their personal settings, files, and workspace, ensuring a personalized and secure experience.

  2. Development and testing: Software developers may use account switching to test their applications in different environments and conditions.

  3. Granting temporary access: If guests or temporary workers need access to the system, switching users provides a convenient and secure way to use the system without creating permanent accounts.

  4. System administration: For system administrators managing and maintaining the system, switching accounts provides access to different user environments, which is essential for various administrative tasks.

In this guide, we'll cover three ways to switch users in Linux. The first two methods use a graphical user interface. The third option describes an alternative method using the terminal, which can be particularly useful for those working on a cloud server or who prefer command-line tools. This way, you can choose the option that best suits your preferences and needs.

Option 1: Switching Users at System Startup

Linux distributions, by default, allow switching users at system startup. If automatic login is enabled, you need to disable it in the settings for the specific user (for Ubuntu: "Settings" → "Users").

  1. Start your Linux machine and wait for it to load. A screen will appear showing a list of available user accounts.

  2. To select the account, click on it.

  3. Enter the password and press "Enter". The system will begin to load.

If you don't see the user you need in the list, use the "Not listed?" button.

  1. In the new window, enter the username you want to log in as and press "Enter". Then, enter the password for the account. If everything is correct, the system will start loading.

If a person already has an active session and doesn't want to restart the system to switch users, there's another option that allows switching without shutting down or rebooting the machine.

Option 2: The "Switch User" Option

This method involves using the "Switch User" button, which opens a window for selecting a user account without restarting the system. This option is typically available in the user menu in the top-right corner of the screen. If you don't find it, consult the official documentation for your Linux distribution.

  1. To switch users in Linux using this option, click on the area in the top-right corner of the screen, as shown below.

  2. In the drop-down menu, select "Power Off / Log Out," and then click "Switch User…".

  3. After following the steps, a list of available users will appear. All subsequent actions are the same as those described in the previous section.

After covering the graphical interface methods, let's move on to the third option, which may interest those who prefer working through the terminal. This method is also suitable for those managing a server with only a terminal interface.

Option 3: Using a Terminal Command

If you're working on a Linux server or prefer using the terminal, this section of the guide is for you. Here, we'll discuss the Linux su command and explain how to use it step by step. The syntax of the command is shown below:

su [options] [username]
  1. Open the terminal on your Linux system. You can use hotkeys (for example, Ctrl + Alt + T) or find the terminal in the applications menu. If you're working on a server, use the available connection tools, such as SSH.

  2. To switch to another user in Linux, type the following into the terminal:

su - username

The - option starts a new shell for the user, similar to how it would look if the user logged in from the start.

  1. After running the command, the system will ask for the account password. Enter it and press "Enter." Note that password characters won't appear on the screen as you type.

  2. If you need to log in as the superuser, run su without parameters:

su

Similarly, enter the superuser password.

  1. When you're done working as the superuser or another account, type:

exit

This command will terminate the session and return you to the previous user.

Conclusion

In this guide, we covered three different ways to switch users in Linux, giving you the flexibility to choose based on your preferences and use case. Switching between accounts efficiently is important for ensuring security, privacy, and convenience when using a Linux system.

Linux
11.09.2024
Reading time: 5 min

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start
Email us