Switching users with su
Command Line – Switching Users

© Lead Image © bee32, 123RF.com
There are more ways to switch users than you may know. The su command offers security and versatility.
The su
(substitute or switch user) command lets you change from the current account to another user or group ID [1]. It can be used for security purposes, such as running the web in a more locked-down account without access to other files, but its most common purpose is to switch from a user account to root in distributions that are not set up to use sudo
. Although the target account must be logged into, using su
requires fewer steps than logging out of one account and into another. When the session is no longer needed, the command exit
will return the terminal to the original account.
su Options
Frequently used to switch from a user account to root, the bare command switches to the root account given, but it does not change the current directory or environment. This option is convenient for small tasks, such as entering a single command, but it can cause problems if the root account differs greatly from the original account. By contrast, adding --login
(-
, -l
) opens a login shell that changes to the target account's home directory (in this case, /root
) and activates the environment variables HOME
, SHELL
, USER
, LOGNAME
, and PATH
(Figure 1). This option can be inconvenient if you plan to work on files in the original directory, but it removes the chance of a problem caused by a change in the environments, making it suited for a longer session in the target account.
However, those who use su
only for either of these purposes might be surprised to discover that the command is more versatile. To start with, su
can specify any account to log in to. The root user can also use --group=GROUP
(-g
) to access all accounts in a group, when, for example, an option such as --command
is used (see the following features list). In addition, a specific shell can be logged into with --shell=shell
(-s
).
[...]
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

News
-
KaOS 2025.05 Officially Qt5 Free
If you're a fan of independent Linux distributions, the team behind KaOS is proud to announce the latest iteration that includes kernel 6.14 and KDE's Plasma 6.3.5.
-
Linux Kernel 6.15 Now Available
The latest Linux kernel is now available with several new features/improvements and the usual bug fixes.
-
Microsoft Makes Surprising WSL Announcement
In a move that might surprise some users, Microsoft has made Windows Subsystem for Linux open source.
-
Red Hat Releases RHEL 10 Early
Red Hat quietly rolled out the official release of RHEL 10.0 a bit early.
-
openSUSE Joins End of 10
openSUSE has decided to not only join the End of 10 movement but it also will no longer support the Deepin Desktop Environment.
-
New Version of Flatpak Released
Flatpak 1.16.1 is now available as the latest, stable version with various improvements.
-
IBM Announces Powerhouse Linux Server
IBM has unleashed a seriously powerful Linux server with the LinuxONE Emperor 5.
-
Plasma Ends LTS Releases
The KDE Plasma development team is doing away with the LTS releases for a good reason.
-
Arch Linux Available for Windows Subsystem for Linux
If you've ever wanted to use a rolling release distribution with WSL, now's your chance.
-
System76 Releases COSMIC Alpha 7
With scores of bug fixes and a really cool workspaces feature, COSMIC is looking to soon migrate from alpha to beta.