LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 09-13-2004, 02:07 PM   #1
the_rhino
Member
 
Registered: Sep 2004
Distribution: PCLinuxOS
Posts: 59

Rep: Reputation: 15
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
 
Old 09-13-2004, 02:08 PM   #2
AAnarchYY
Member
 
Registered: Sep 2004
Location: Carlisle, MA
Distribution: Debian 8
Posts: 419

Rep: Reputation: 30
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.

Last edited by AAnarchYY; 09-13-2004 at 02:10 PM.
 
Old 09-13-2004, 02:16 PM   #3
the_rhino
Member
 
Registered: Sep 2004
Distribution: PCLinuxOS
Posts: 59

Original Poster
Rep: Reputation: 15
Okay, so there is a difference. I don't understand login shell compared to swapping user. Will any one explain this for me?
 
Old 09-13-2004, 02:28 PM   #4
AAnarchYY
Member
 
Registered: Sep 2004
Location: Carlisle, MA
Distribution: Debian 8
Posts: 419

Rep: Reputation: 30
mostly environment variables, paths, and the such
 
Old 09-13-2004, 02:51 PM   #5
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 683

Rep: Reputation: 63
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
 
Old 09-13-2004, 02:53 PM   #6
AAnarchYY
Member
 
Registered: Sep 2004
Location: Carlisle, MA
Distribution: Debian 8
Posts: 419

Rep: Reputation: 30
lol thank you for illustrating my point :P
 
Old 09-13-2004, 02:57 PM   #7
the_rhino
Member
 
Registered: Sep 2004
Distribution: PCLinuxOS
Posts: 59

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Shell Scripting Question hellomynameisphil Programming 2 08-27-2005 04:41 AM
simple c-shell question mathias1979 Programming 1 06-27-2005 05:51 PM
probably a simple shell question odious1 Linux - General 6 03-03-2004 11:06 AM
simple question on shell script gsbarry Linux - General 2 05-23-2003 05:09 AM
simple shell script question mathfeel Linux - General 12 03-06-2003 12:23 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration