APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

2003/12/10 su


© December 2003 Tony Lawrence

Switch User

Without any arguments, this assumes you want to become "root", which is probably most of what it is used for. It will ask for the password (root's password if you haven't specified a user) and if you can give that, you will effectively become the other user.

I say "effectively" because this is NOT exactly the same as logging in as the user. For one thing, with just "su", you keep your own environment (PATH, etc.). That's something that throws new users often: use "su -" and you will pick up the login environment.

Anthony-Lawrences-Computer:~ apl$ echo $PATH
/bin:/sbin:/usr/bin:/usr/sbin:/Users/apl/bin:/usr/local/bin:/Developer/Tools
Anthony-Lawrences-Computer:~ apl$ su
Password:
[Anthony-Lawrences-Computer:/Users/apl] apl# echo $PATH
/bin:/sbin:/usr/bin:/usr/sbin:/Users/apl/bin:/usr/local/bin:/Developer/Tools
[Anthony-Lawrences-Computer:/Users/apl] apl# exit
Anthony-Lawrences-Computer:~ apl$ su -
Password:
[Anthony-Lawrences-Computer:~] root# echo $PATH
/bin:/sbin:/usr/bin:/usr/sbin
[Anthony-Lawrences-Computer:~] root# 
 

Also, it's your effective uid that is changed. Programs can, if they want to, distinguish between real and effective id's, so it is possible that some program will not work using su.

The "su -" is useful if you are root, and need to login as some other user. Because you are root, you don't need their password: "su - bill" will act just like bill logging in.


Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

->
-> su


Inexpensive and informative Apple related e-books:

Take Control of Parallels Desktop 12

Sierra: A Take Control Crash Course

Take Control of Upgrading to El Capitan

Photos: A Take Control Crash Course

Take Control of iCloud, Fifth Edition




More Articles by © Tony Lawrence




Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us


Printer Friendly Version





The man who receives five thousand dollars a year wants six thousand dollars a year, and the man who owns eight or nine hundred thousand dollars will want a hundred thousand dollars more to make it a million, while the man who has his millions will want everything he can lay his hands on and then raise his voice against the poor devil who wants ten cents more a day. (Samuel Gompers)




Linux posts

Troubleshooting posts


This post tagged:

Scripting

Shell

UnixWords



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode