/ factorpad.com / tech / linux-essentials / su-command.html
An ad-free and cookie-free website.
Beginner
Learn to temporarily change users at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux su Command Summary with Examples (3:12)
Our seventy-eighth word, or command to memorize is
su
from our category
Users.
su
allows you to temporarily
substitute users.
-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.
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.
So we switched to her home directory.
Then, let's run a whoami
, from video
(tutorial) 13.
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.
And then to leave her account we'll need to type
exit
.
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.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
Please join our growing community and give back if you found value in this free knowledge.
id
command, hit Back.sudo
command, click Next./ factorpad.com / tech / linux-essentials / su-command.html
A newly-updated free resource. Connect and refer a friend today.