LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 11:28 AM   #1
sigint-ninja
Member
 
Registered: Feb 2011
Location: Republic Of Ireland
Distribution: Debian,Centos,Slackware
Posts: 508

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, 12:02 PM   #2
jbuckley2004
Member
 
Registered: Aug 2004
Distribution: Fedora (KDE spin)
Posts: 224

Rep: Reputation: 70
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, 12:07 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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 12:09 PM.
 
1 members found this post helpful.
Old 08-08-2016, 01:09 PM   #4
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
"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, 12:02 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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



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 10:38 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
Open Source Consulting | Domain Registration