LinuxQuestions.org
Help answer threads with 0 replies.
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 08-08-2016, 12:28 PM   #1
sigint-ninja
Member
 
Registered: Feb 2011
Location: Republic Of Ireland
Distribution: Debian,Centos,Slackware
Posts: 485

Rep: Reputation: 29
when to use su or su-


hi guys,

just reading in the Dutchmans Red Hat manual,

it says:

When using su , a sub shell is started. This is an environment where you are able to work as the target user account, but environment settings for that user account have not been set. If you need complete access to the entire environment of the target user account, you can use su - to start a login shell. If you start a login shell, all scripts that make up the user environment are processed, which makes you work in an environment that is exactly the same as when logging in as that user.

thats all fine,and i understand it...

but when would you want to login with the complete user environment,and when wouldnt you?

is it more to do with bash scripting and testing things?
 
Old 08-08-2016, 01:02 PM   #2
jbuckley2004
Member
 
Registered: Aug 2004
Distribution: Fedora (KDE spin)
Posts: 157

Rep: Reputation: 50
Hum...
I always kinda, sorta assumed the su - form was expressly to let you use your accounts locally defined environment variables. Back in the days of HP and Sun workstations, that seemed like reason enuf.

Was I wrong in thinking that?
 
Old 08-08-2016, 01:07 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,552

Rep: Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112
Use "su" when you're currently doing something that temporarily needs root permission, eg: you just ran make and now need to run make install. "su" will leave your environment and working directory alone so you can simply run "make install" after the su, without having to cd all over the place and possibly copy/paste any necessary environment variable declarations for the build to work correctly.

Use "su -" when you need to do a task as root that has nothing to do with what you've been doing previously in the terminal, in which having a clean shell with root's proper PATH and other environment variables would be beneficial (eg: /sbin and /usr/sbin are usually not in regular users' PATH, so you want to use "su -" to load up root's full environment to have access to those programs).

Last edited by suicidaleggroll; 08-08-2016 at 01:09 PM.
 
1 members found this post helpful.
Old 08-08-2016, 02:09 PM   #4
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,225

Rep: Reputation: 2521Reputation: 2521Reputation: 2521Reputation: 2521Reputation: 2521Reputation: 2521Reputation: 2521Reputation: 2521Reputation: 2521Reputation: 2521Reputation: 2521
"su -" is just the short form of this command
Code:
su -l root
su you become root BUT!!!! with your users $PATH and system settings
as above any program in /sbin you need to be fully logged in as root
 
Old 08-09-2016, 01:02 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,412

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Actually, su <anyuser> logs you in as anyuser, but with your env not theirs. No user specified defaults to root.

"su - <user>" logs you in as anyuser with THEIR env. No user specified defaults to root (with root's env).
 
  


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



LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:35 PM.

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