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

Become su in Terminal - HowTo - openSUSE Forums

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.

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

man su

. Wikipedia also explains it nicely. su (Unix) - Wikipedia, the free encyclopedia

I hope this helps a bit.

When you want to use it to get root priviliges

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.

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.

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

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).

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:


su -
kwrite /etc/X11/xorg.conf

Before I tried this way:


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.

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:)

I suppose simple way to run graphical apps with root (or someone elses) privileges in KDE environment would be ‘kdesu’. See ‘kdesu --help’ .

Indeed. this has been well discussed in other threads.

sudo :stuck_out_tongue:

Just kidding :smiley:

Yes, that is a good remark. Thank you.

Though, kdesu had some problems in my system with earlier KDE 4 versions (password dialog did not show up if I remember correctly).

Now it works fine, as I see (KDE 4.4.3). So indeed kdesu should be the preferred method.