Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: su or su - ???

  1. #1
    Join Date
    Feb 2010
    Location
    NH-USA
    Posts
    240

    Default su or su - ???

    So why is su preferred over su - ?

    I'm a new Linux user, and thus far I am under the impression that su gives you root permissions, with some background processes still in normal status, but su - would give you " absolute root " whereas you have all processes across the board in some sort of grandmaster champ ( for lack of a better term, really...) status of root.

    I know that su is the preffered way, but why is su - so different, and should be avoidable.....is su - going to make it that much easier, and quicker, to destroy everything for the clueless like myself???



    -cheers

  2. #2
    Join Date
    Jun 2008
    Location
    The English Lake District. UK - GMT/BST
    Posts
    37,022
    Blog Entries
    16

    Default Re: su or su - ???

    My openSUSE 13.1 KDE Box
    My Articles
    Was I any help? If yes: Click the star below

  3. #3
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,941
    Blog Entries
    4

    Default Re: su or su - ???

    su - gives you a login like you would get at the terminal, including root's $PATH and other environment, whereas su is with your own environment. This is important when you want to have the same experience as the user in question. BTW, su isn't limited to becoming root, you can use to "be" another account, for which you need the password, or to be root at the time. This can be useful for debugging another user's problems.

  4. #4
    Join Date
    Jun 2008
    Posts
    2,042
    Blog Entries
    1

    Default Re: su or su - ???

    su means substitute user. So while it is most often used to gain root access, it can be used to become another user if there is more than one user account.

    Lets say you have user account one as Joe, and user account two as Jane, and of course you have root. If you use su and enter roots password, then you will become root, having all the access of root. On the other hand if you su and enter the password for Jane's account, then you will be operating with the privileges that are given to Jane.

    As explained by others, the - as su just puts you in that environment. So if yo need to be in roots directory when entering root, not the directory where you currently are, then entering the - would be an appropriate choice.

    I would encourage you to read the man page. su(1): run shell with substitute user/group IDs - Linux man page You can also find this man page on your system by typing
    Code:
    man su
    . Wikipedia also explains it nicely. su (Unix) - Wikipedia, the free encyclopedia

    I hope this helps a bit.
    ______________________________________________________________________________________
    Don't ask "if" something can be done, for it can always be done. Rather instead ask "How" can it be done.

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    15,697

    Default Re: su or su - ???

    Quote Originally Posted by subcook69420 View Post
    So why is su preferred over su - ?

    I'm a new Linux user, and thus far I am under the impression that su gives you root permissions, with some background processes still in normal status, but su - would give you " absolute root " whereas you have all processes across the board in some sort of grandmaster champ ( for lack of a better term, really...) status of root.

    I know that su is the preffered way, but why is su - so different, and should be avoidable.....is su - going to make it that much easier, and quicker, to destroy everything for the clueless like myself???



    -cheers
    When you want to use it to get root priviliges
    Code:
    su -
    is definitely the prefered way and thus completely reversed from what you suggest above. It avoids all sorts of potential security problems.

    See also: SDB:Login as root - openSUSE and several discussion about it here in the Forums (you did search for them before you asked this, did you?).

    Also you should have studied the man pages before you asked here. And then may be ask here for those things unclear after reading the man pages.
    Henk van Velden

  6. #6

    Default Re: su or su - ???

    The advice given here is not wrong, but I don't think it has gone far enough. It's also a bit unfair to refer to the man pages, as they are generally only useful as a reference for someone who already knows how things work; they rarely explain things sufficiently for the novice (*especially* those written by David MacKenzie). For example, the man page (single page in this case) doesn't fully explain the significance of the '-' after the 'su'.

    It all boils down to whether you want to maintain the normal user's environment and get root priveleges (su), or adopt the root user's environment and priveleges. There is no hard and fast rule for all occasions; it depends on what you want to achieve.

    An example of wanting to maintain the normal user's environment is when you are compiling a program. The first part - 'make' - is usually done under your normal user's privileges. But when you want to 'make install', you need root privileges to install the program's files to their various directories. However, you want to maintain the user's environment variables and current working directory, as the 'make install' will depend on environment variables exported to the user's environment by the 'make' command. If you performed a 'su -' here, the current working directory would change to '/root', and the environment variables would also change to those owned by root; all the 'compiled' variables would be invisible to this root user. This would cause the 'make install' command to fail.

    On the other hand, if you want to perform system administration (such as change the system settings in /etc, or run commands to change a configuration), then the appropriate command is 'su -', so that all of root's environment variables ($PATH, etc) are activated. Using 'su' here will not result in all of root's environment variables being adopted. The risk with that is that some of the commands won't be found, or they won't execute correctly.

  7. #7
    Join Date
    Feb 2010
    Location
    NH-USA
    Posts
    240

    Default Re: su or su - ???

    very good clarification, thank you. Now I can chose a 'lil wiser

  8. #8

    Default Re: su or su - ???

    That is a command which I just learned under Linux. After trying to setup the network under Solaris 10 I gave up and installed Linux on that computer. There is other information which goes with the SU command such as installing software with the Root access. All this is new to me since I normally work in Windows, and OS/2 (eComstation).

  9. #9
    Join Date
    Jun 2008
    Location
    Tallinn, Estonia
    Posts
    265

    Default Re: su or su - ???

    Thread is little bit old, but I just want to say thanks to subcook69420 for raising the question and striven for good clarification.

    Now I know how to run KDE 4 versions of kwrite and konqueror as root, when I need some system configuration tweaking. For example to start kwrite as root:
    Code:
    su -
    kwrite /etc/X11/xorg.conf
    Before I tried this way:
    Code:
    su
    kwrite /etc/X11/xorg.conf
    Which worked with KDE 3 version of kwrite, but failed with KDE 4 version. The same applies to Konqueror.

  10. #10
    Join Date
    Jun 2008
    Location
    The English Lake District. UK - GMT/BST
    Posts
    37,022
    Blog Entries
    16

    Default Re: su or su - ???

    You will be pleased to know that in kde4.5 that I am running now. Super User Dolphin opens and edits root files no problem
    My openSUSE 13.1 KDE Box
    My Articles
    Was I any help? If yes: Click the star below

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •