How to Switch Users on the Debian 12 Bookworm System

Learn how to switch between users on the Debian 12 Bookworm system using various methods and tools.

Managing multiple users is a critical aspect of using Linux-based operating systems like Debian 12 Bookworm. Whether you’re an individual sharing your system with family members, a system administrator managing various user accounts, or a developer working in different environments, the ability to switch between users efficiently is essential.

In this article, we’ll explore how to switch users on the Debian 12 Bookworm system, covering both command-line and graphical interfaces. We’ll also touch on best practices, related user management concepts, and troubleshooting tips to ensure a smooth experience.


Table of Contents

  1. Introduction to User Management in Debian
  2. Understanding User Switching
  3. Switching Users via Terminal (CLI)
    • Using su
    • Using sudo -i
    • Using login
    • Using ssh localhost
  4. Switching Users in the GNOME Desktop Environment
  5. Managing Permissions and Groups
  6. Creating and Deleting Users
  7. Troubleshooting Common Issues
  8. Security Considerations
  9. Final Thoughts

1. Introduction to User Management in Debian

Debian is a multi-user operating system that supports simultaneous users with isolated environments. Every user account has its own home directory, settings, and permissions. Managing users efficiently is essential in ensuring system security and usability.

Debian 12, codenamed Bookworm, includes user management tools compatible with systemd and the GNOME desktop environment by default. However, the concepts apply equally well to other desktop environments and headless server setups.


2. Understanding User Switching

Switching users involves moving from the current user session to another without logging out or restarting the system. There are two main contexts for switching users:

  • Command-Line Interface (CLI): Useful when managing servers or when accessing a terminal in desktop environments.
  • Graphical User Interface (GUI): Convenient for desktop users who want to switch sessions without terminal commands.

You can switch users to gain temporary administrative access (root), to test configurations under another user, or simply to work in a different environment.


3. Switching Users via Terminal (CLI)

Let’s go through several common ways to switch users via the command line.

a. Using su (Substitute User)

The su command allows you to switch to another user account. By default, it switches to the root user.

Syntax:

su - username

Example:

su - john

You’ll be prompted to enter the password of the target user (john in this case). Once authenticated, you’ll be placed in their login shell.

To return to your original user:

exit

Tip: Use the - option to simulate a full login shell of the target user, ensuring their environment variables and paths are properly set.

b. Using sudo -i

If your user is part of the sudo group, you can gain root access without knowing the root password.

sudo -i

This gives you an interactive login shell as the root user. This method is more secure and is often the recommended approach over enabling the root account directly.

You can also switch to another user with:

sudo -u username -i

Example:

sudo -u john -i

Note: The user executing this command must be allowed by the sudoers policy.

c. Using login

If you’re on a virtual terminal (tty), you can use the login command.

login username

You’ll be prompted for the target user’s password, and then switched over.

d. Using ssh localhost

Another neat trick is to SSH into your own machine:

ssh username@localhost

This is useful when testing SSH access configurations, key-based authentication, or working on headless systems.


4. Switching Users in the GNOME Desktop Environment

Debian 12 Bookworm typically comes with the GNOME desktop environment, which supports fast user switching through a graphical interface.

Steps to Switch Users in GNOME

  1. Click on the top-right corner (system menu) where your username or power icon is shown.
  2. Click on your username or profile icon.
  3. Select Switch User from the dropdown.
  4. You’ll be taken to the login screen where you can choose another user to log in as.
  5. Log in with their credentials.

Your original session is preserved, so you can switch back without losing work.

Lock vs Switch

  • Lock: Secures the current session.
  • Switch User: Opens a new session for another user without ending the first one.

5. Managing Permissions and Groups

Switching users is often linked with permissions and group memberships.

Check Group Membership

groups username

Example:

groups john

If you want a user to have administrative privileges (e.g., to use sudo), add them to the sudo group:

sudo usermod -aG sudo john

Always verify permissions when you experience “permission denied” issues.


6. Creating and Deleting Users

Knowing how to manage users can help when setting up multi-user environments.

Creating a User

sudo adduser john

This creates a home directory (/home/john), sets permissions, and prompts for a password.

Deleting a User

sudo deluser john

To delete their home directory as well:

sudo deluser --remove-home john

7. Troubleshooting Common Issues

1. Permission Denied when Switching Users

  • Make sure the target user exists.
  • Confirm correct password.
  • Check group memberships (/etc/sudoers, /etc/group).

2. Can’t Switch to Root

  • Root account might be disabled by default.
  • Use sudo -i instead.
  • Enable root only if absolutely necessary:
sudo passwd root

3. User Not Listed on Login Screen

  • Make sure the user account is not marked as a “system” user.
  • GUI login managers often hide system users by default.

8. Security Considerations

Switching users should be done securely and responsibly. Here are some important tips:

  • Avoid enabling direct root login unless required.

  • Use sudo for temporary admin access.

  • Protect your user sessions with strong passwords or passkeys.

  • Use whoami and id to verify your current user:

    whoami
    id
    
  • Monitor user logins:

    last
    
  • Restrict access with proper file permissions and group policies.


9. Final Thoughts

Switching users on Debian 12 Bookworm is a fundamental but powerful feature. Whether you’re working from the terminal or within a GNOME session, Debian offers multiple efficient ways to handle user context changes.

From basic commands like su and sudo, to graphical switching in GNOME, and even using SSH or login for remote or virtual terminal environments—knowing how to switch users effectively enhances your productivity, security, and control over the system.

For system administrators and everyday users alike, mastering this process is key to unlocking Debian’s multi-user capabilities.