Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » Linux » How to Switch between Users in Linux
  • linux tux minimalism 4k 42 2560x1700 1 1
    Warning useradd: the home directory already exists. Not copying any file from skel director into it Linux
  • GitVulfix456zgfbn
    Git Vulnerability: Git for Windows uninstaller is vulnerable to DLL hijacking when run under the SYSTEM user account Version Control System
  • kerberosdelegation
    Kerberos Delegation: A Comprehensive Guide Web Server
  • fimage2
    How to install and configure JIRA on Linux Linux
  • enable or disable WinRM
    How to enable or disable WinRM via the command-line Network | Monitoring
  • The evolution of Windows authentication   NTLM to Keberos
    Bidding Farewell to NTLM in favour of Kerberos Windows
  • DNS
    DNS uses TCP and UDP Network | Monitoring
  • Add additional Windows drives
    How to Add Another Hard Drive to a Virtual Machine in HyperV  Virtualization

How to Switch between Users in Linux

Posted on 31/10/202201/07/2023 Raphael Gab-Momoh By Raphael Gab-Momoh No Comments on How to Switch between Users in Linux
switchlinuxusers

Using the Linux command su (switch user), you can execute a command as a different user. This is the quickest way to switch to the administrative account when logged in as the most recent session. To make the code safer, all Linux distributions—including Ubuntu—disable the root user account by default. This limitation, however, would prevent the user from carrying out intricate instructions. You can overcome this restriction can by briefly assuming root user status via su. If you’ve ever asked this question, how do I switch users in Linux? Then, you’re in the right place.

Continue reading if you want to learn more about the su and sudo commands, including how to switch between users in Linux. This article will cover all aspects of the sudo command and how to utilize it in Linux. Find other articles here: Rename or Move a File or Directory in Linux and How to Install and use Minikube on a Linux System and How to launch a free WordPress test site with TasteWP? and How to launch a free WordPress test site with TasteWP? also How to Install PlayonLinux on a Linux System

Prerequisites to Switching Between Users in Linux

You will need terminal access and an account with sudo privileges on the Linux-based system.

Changing the Current User Using su

During a login session, the su command can be used to either change into a different user or to become the superuser. The command’s fundamental syntax is as follows:

su options username

Options refer to the many flags that can be applied to a command, and username denotes the name of the target account. Su will automatically switch to the root user if the username is left out of the command.

su

The system will automatically transfer the current login session to the chosen user by simply giving the username as an argument. Note: Switching between users on Linux is made a lot easier with these steps.

su username 

The the screenshot below, we switched to a user named rdgmh

how to switch between users in Linux- su
switching between users

Notice that we had to input our password. The password of the current user that you are logged into . We can verify the change with the command:

whoami
echo $USERNAME
how to switch between users in Linux-rdgm
whoami

The output will display the name of the user you just switched to. In this case: rdgmh

You don’t need to switch to another user if you simply need to execute one command as that user. Instead, you may just use the -c switch to run the command as a different user.

su -c <command> <username>

When switching between users in Linux, the su command can establish a new environment by prefixing it with a hyphen (-).

how to switch between users in Linux-wooo
su -c

the user account is not for rdgmh, but we ran whoami and we were asked for rdgmh’s password instead of the logged in account and we were shown the result below.

how to switch between users in Linux-shell
-s flag

To switch to a different user in Linux while changing the shell, use the -s parameter with the command. Keep in mind that you must execute the command with the appropriate shell path:

Using the Desktop Environment to Switch Users in Linux

The graphical method is an alternative. The desktop environment that most Linux computers have installed gives you the graphical user interface you need to interact with the OS.

Switching between users in the GNOME desktop environment:

  1. The top-right corner of the screen has a downward-pointing arrow icon; click on it.
  2. Switch User from the dropdown menu by clicking Power Off/Log Out.
gui
switching from gui

We have the option of chosing which ever user we want to use as GNOME will display a list of available users. Click on the username you want to log in as

how to switch users between in Linux=users
user options

Summary

It is possible to switch between different users when using Linux . You can follow the steps and the laid down approaches for whichever method you want to use.

Rate this post

Thank you for reading this post. Kindly share it with others.

  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on Bluesky (Opens in new window) Bluesky
  • Click to share on Threads (Opens in new window) Threads
  • Click to share on Nextdoor (Opens in new window) Nextdoor
Linux Tags:sudo

Post navigation

Previous Post: Find BIOS Serial Number and System Information on Windows 11
Next Post: Best Way to Backup Dropbox to Box

Related Posts

  • Screenshot 2021 02 05 at 22.40.51
    Disable automatic screen lock on Ubuntu Desktop Linux
  • discorddd
    Discord Installation Guide for Linux System Linux
  • Slide1 1
    Create Multiple Users with Passwords in Ubuntu Linux Linux
  • FEAUREanydesk
    How to install AnyDesk on a Linux Machine Linux
  • feature image sublime text 4
    How to install Sublime Text 4 on Ubuntu Linux
  • Synergy software kvm
    Why Software KVMs such as Synergy is replacing Hardware KVMs Linux

More Related Articles

Screenshot 2021 02 05 at 22.40.51 Disable automatic screen lock on Ubuntu Desktop Linux
discorddd Discord Installation Guide for Linux System Linux
Slide1 1 Create Multiple Users with Passwords in Ubuntu Linux Linux
FEAUREanydesk How to install AnyDesk on a Linux Machine Linux
feature image sublime text 4 How to install Sublime Text 4 on Ubuntu Linux
Synergy software kvm Why Software KVMs such as Synergy is replacing Hardware KVMs Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

sysadmin top30a
 
  • linux tux minimalism 4k 42 2560x1700 1 1
    Warning useradd: the home directory already exists. Not copying any file from skel director into it Linux
  • GitVulfix456zgfbn
    Git Vulnerability: Git for Windows uninstaller is vulnerable to DLL hijacking when run under the SYSTEM user account Version Control System
  • kerberosdelegation
    Kerberos Delegation: A Comprehensive Guide Web Server
  • fimage2
    How to install and configure JIRA on Linux Linux
  • enable or disable WinRM
    How to enable or disable WinRM via the command-line Network | Monitoring
  • The evolution of Windows authentication   NTLM to Keberos
    Bidding Farewell to NTLM in favour of Kerberos Windows
  • DNS
    DNS uses TCP and UDP Network | Monitoring
  • Add additional Windows drives
    How to Add Another Hard Drive to a Virtual Machine in HyperV  Virtualization

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,841 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.