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.
More Articles by Tony Lawrence © 2011-07-06 Tony Lawrence
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)