Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
the - makes it into a login shell as opposed to simply swaping users
Quote from the first paragraph of the su man entry
Quote:
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.
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)
Illustrated:
blink@sanity ~ --> su
Password:
[root@sanity blink]# fdisk -l /dev/hda
bash: fdisk: command not found
[root@sanity blink]# exit
exit
blink@sanity ~ --> su -
Password:
[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
Password:
[root@sanity blink]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/blink/bin
[root@sanity blink]# exit
exit
blink@sanity ~ --> su -
Password:
[root@sanity root]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.