LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Confused as to when to use the dash with su (https://www.linuxquestions.org/questions/linux-newbie-8/confused-as-to-when-to-use-the-dash-with-su-4175560582/)

kb2tfa 12-03-2015 09:05 PM

Confused as to when to use the dash with su
 
I am confused. I see some tutorials that show using the dash with su to incorporate the users' path with the root path. That's how I understood it, but when I print them out, it's not the case. It appears the "su -" is the root path with no user paths.

Code:

PLAIN SU PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/ron/.local/bin:/home/ron/bin

RON PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/ron/.local/bin:/home/ron/bin

SU DASH PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin


John VV 12-03-2015 09:32 PM

that dash is a keybord shortcut for this command
Code:


" su - "
is the same as
" su -l root "

su is root BUT!!!! with your normal user $PATH and in the same folder
"su -" is root BUT a log in AS!!! root and you are in the root HOME folder ( /root)

to install software you build you use "su" NO DASH , because you need to still be in the same folder

but to say launch Gedit AS ROOT you will NEED the dash
-- try it --
Code:

su
gedit

and open a new terminal
Code:

su -
gedit

both fedora and cent use /usr/sbin
this folder IS NOT !!! in the normal users system path
but it is in root's

so for all the programs in that folder you need to be loged in as root ( use the dash )

kb2tfa 12-03-2015 09:58 PM

Thank you I see the difference

kb2tfa 12-03-2015 09:59 PM

I ran pwd from both, and I see the difference. I didn't notice before the folder changed.

chrism01 12-03-2015 10:51 PM

... and of course you can specify any target user if you know their passwd eg
Code:

su - fred
will log you in as fred, with HIS env, home dir etc.

Note also that if you are starting from the root acct, the above will not require specifying fred's passwd; useful for starting processes as another user during eg boot.

jheengut 12-03-2015 11:58 PM

I thought the ~/.profile or ~/.bashrc files are not run when su is specified without dash.


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