-   Linux - Newbie (
-   -   A shell command simple question (

the_rhino 09-13-2004 01:07 PM

A shell command simple question
When I first started learning Linux shell commands I was told to type "su -" enter at the prompt to get super user password login. I have simply typed "su" enter and get the same thing.

Is there a specific important reason to type "su -" rather than "su"?

I did not find any information in the man page to explain this.

Thanks for any answers,

The Rhino

AAnarchYY 09-13-2004 01:08 PM

the - makes it into a login shell as opposed to simply swaping users

Quote from the first paragraph of the su man entry


su is used to become another user during a login session.
Invoked without a username, su defaults to becoming the
super user. The optional argument - may be used to provide
an environment similiar to what the user would expect had
the user logged in directly.

the_rhino 09-13-2004 01:16 PM

Okay, so there is a difference. I don't understand login shell compared to swapping user. Will any one explain this for me?

AAnarchYY 09-13-2004 01:28 PM

mostly environment variables, paths, and the such

Blinker_Fluid 09-13-2004 01:51 PM

I always use su - that way I don't have to remember that normal users don't have /sbin and a few other directories in the path by default. (yes I know I could add them for normal users)

blink@sanity ~ --> su
[root@sanity blink]# fdisk -l /dev/hda
bash: fdisk: command not found
[root@sanity blink]# exit
blink@sanity ~ --> su -
[root@sanity root]# fdisk -l /dev/hda

Disk /dev/hda: 120.0 GB, 120000000000 bytes
16 heads, 63 sectors/track, 232514 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 203 102280+ 83 Linux
/dev/hda2 204 40838 20480040 83 Linux
/dev/hda3 40839 81473 20480040 83 Linux
/dev/hda4 81474 232514 76124664 f W95 Ext'd (LBA)
/dev/hda5 81474 101791 10240240+ 83 Linux
/dev/hda6 101792 122108 10239736+ 83 Linux
/dev/hda7 122109 126171 2047720+ 82 Linux swap
/dev/hda8 126172 129219 1536160+ 83 Linux
/dev/hda9 129220 197037 34180240+ 83 Linux
/dev/hda10 197038 232514 17880376+ 83 Linux
[root@sanity root]#

The difference with the PATH:
blink@sanity ~ --> su
[root@sanity blink]# echo $PATH
[root@sanity blink]# exit
blink@sanity ~ --> su -
[root@sanity root]# echo $PATH

AAnarchYY 09-13-2004 01:53 PM

lol thank you for illustrating my point :P

the_rhino 09-13-2004 01:57 PM

Thanks! That sure makes it easier to understand the difference is pretty big. So I need to start using su - from now on.

All times are GMT -5. The time now is 07:07 AM.