FactorPad
Build a Better Process

Linux su Command Summary with Examples

Linux su allows you to temporarily substitute users.
  1. Purpose - Learn what su is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with su.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 24, 2021
In this tutorial on Linux su, 78 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / su-command.html


An ad-free and cookie-free website.


Examples of the Linux su Command

Beginner

Learn to temporarily change users at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux su Command Summary with Examples (3:12)

Video Script

The Command and Why You Need It

Our seventy-eighth word, or command to memorize is su from our category Users.

su allows you to temporarily substitute users.

Common Linux su Options
-options description
-h, --help Print help screen
-, -l, --login Run login scripts as another user
-m, -p, --preserve-environment Keep the same shell and environment

Recall from the previous four videos (tutorials) we tackled file permissions and ownership, now we'll attempt to login as another user, say to perform a task.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The su command has 5 options, and the argument is the User ID (name) you'd like to use temporarily.

Like most commands, help is available with double-dash --help. The - or -l option logs in as if you were the other person. -m or -p keeps your own shell, ignoring that person's startup scripts and environment variables.

So why is su an important command? Well, many administrative commands like seeing log files, installing programs and modifying configuration files can only be accessed with new credentials. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. In the time we have, let's keep it very simple. Start with su jennifer, enter her password and then a pwd from video (tutorial) 6 to see where we sit.

$ su jennifer Password: $ pwd /home/jennifer

So we switched to her home directory.

Then, let's run a whoami, from video (tutorial) 13.

$ whoami jennifer

And notice how I've taken the identity of Jennifer.

And last, enter the id command from video (tutorial) 77 for Jennifer's group memberships.

$ id uid=1001(jennifer) gid=1001(jennifer) groups=1001(jennifer)

And then to leave her account we'll need to type exit.

$ exit $ _

A Final Tip

Okay now you know how to use su. And you know the syntax for commands, options and arguments.

One last tip about the su command. So I touched on passwords a second ago, which we'll tackle right after one more related and important command.

Okay, thanks for visiting today. I hope this was a helpful introduction to the su command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

Please join our growing community and give back if you found value in this free knowledge.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / su-command.html


linux su command
sudo linux su
sudo su
su linux
su command
linux su examples
su root
su user
sudo su root
su password
change user linux
root su
man su
add sudoer
switch user linux
linux change user

A newly-updated free resource. Connect and refer a friend today.