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
-
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.
-
OpenMandriva Lx 6.0 Available for Installation
The latest release of OpenMandriva has arrived with a new kernel, an updated Plasma desktop, and a server edition.
-
TrueNAS 25.04 Arrives with Thousands of Changes
One of the most popular Linux-based NAS solutions has rolled out the latest edition, based on Ubuntu 25.04.
-
Fedora 42 Available with Two New Spins
The latest release from the Fedora Project includes the usual updates, a new kernel, an official KDE Plasma spin, and a new System76 spin.
-
So Long, ArcoLinux
The ArcoLinux distribution is the latest Linux distribution to shut down.
-
What Open Source Pros Look for in a Job Role
Learn what professionals in technical and non-technical roles say is most important when seeking a new position.
-
Asahi Linux Runs into Issues with M4 Support
Due to Apple Silicon changes, the Asahi Linux project is at odds with adding support for the M4 chips.
-
Plasma 6.3.4 Now Available
Although not a major release, Plasma 6.3.4 does fix some bugs and offer a subtle change for the Plasma sidebar.