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 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:
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.
Development and testing: Software developers may use account switching to test their applications in different environments and conditions.
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.
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.
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").
Start your Linux machine and wait for it to load. A screen will appear showing a list of available user accounts.
To select the account, click on it.
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.
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.
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.
To switch users in Linux using this option, click on the area in the top-right corner of the screen, as shown below.
In the drop-down menu, select "Power Off / Log Out," and then click "Switch User…".
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.
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]
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.
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.
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.
If you need to log in as the superuser, run su
without parameters:
su
Similarly, enter the superuser password.
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.
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.