LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-30-2014, 10:54 AM   #1
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Rep: Reputation: Disabled
su versus su -


I understand that the second command sets all the environmental variables to the defaults for aUserID, while the first will not. What is the implications of doing so?

Code:
su aUserID

su - aUserID
 
Old 03-30-2014, 01:05 PM   #2
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
Its more of a security/convenience. As a admin, when you are attending regular user's grievances, you want to stay in their environment, PATH and the directory in question. The only edge you want is to run as root, which regular users cant.

You don't want to 'su -', where it throws you to /root directory, puts root user's environment and root's PATH, which to be frankly wont let you see the problem from user's perspective.
 
1 members found this post helpful.
Old 03-30-2014, 01:24 PM   #3
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Original Poster
Rep: Reputation: Disabled
Thanks mddesai, very well explained.

I think I better now understand John's post.

So, if I set up my server to prevent ssh'ing as root, and I want to do general configuration as the root user, then I should always use "su - root"?
 
Old 03-30-2014, 02:27 PM   #4
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
Quote:
Originally Posted by NotionCommotion View Post
Didn't mean no difference in "su" and "su -", but no difference with the outcome.
The reason there is no difference with outcome is, unlike all other distro, Redhat includes /sbin directory in PATH of regular users. I don't know why they do it.

Also, while we are in switching users, you also need to know the difference between 'whoami' and 'who am i'. its helps a lot. The following should be self explanatory.

Code:
[madhu@server ~]$ whoami
madhu

[madhu@server ~]$ who am i
madhu    pts/1        2014-03-31 00:43 (192.168.122.1)

[madhu@server ~]$ su - tom
Password: 
[tom@server ~]$ whoami
tom

[tom@server ~]$ who am i
madhu    pts/1        2014-03-31 00:43 (192.168.122.1)

[tom@server ~]$ su - dummy
Password: 
[dummy@server ~]$ whoami
dummy

[dummy@server ~]$ who am i
madhu    pts/1        2014-03-31 00:43 (192.168.122.1)
Quote:
Originally Posted by NotionCommotion View Post
So, if I set up my server to prevent ssh'ing as root, and I want to do general configuration as the root user, then I should always use "su - root"?
Correct, its the recommended way of doing it. But just 'su -' is enough. You should not allow root to ssh. I hope you are aware of 'PermitRootLogin no' in sshd_config.

Last edited by Madhu Desai; 03-30-2014 at 02:36 PM.
 
Old 03-30-2014, 02:47 PM   #5
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Original Poster
Rep: Reputation: Disabled
Thanks again mddesai,

Yes, I am using Centos (i.e. Redhat). Good to know about how they are unique in including /sbin directory in PATH of regular users. Hopefully, I will remember when I try another distro Better yet, I will just get in the habit of using su - right now!

Turns out "who am i" is the same thing as "who". Am I missing anything? So, "who" displays the originally logged on user, and "whoami" displays the current. Again, good to know.

And yes, I am aware of 'PermitRootLogin no' in sshd_config, but thank you for ensuring.

Cheers
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: OpenOffice versus LibreOffice versus The World LXer Syndicated Linux News 0 03-05-2013 11:30 PM
LXer: TLWIR 35: Open Versus Closed Mobility â?? The Nokia N900 Versus The Nokia Lumia 900 LXer Syndicated Linux News 0 04-07-2012 06:31 PM
SAMBA versus VM r2coder Linux - Newbie 4 12-22-2010 04:43 PM
[SOLVED] bash - versus --perl - versus python ow1 Linux - Software 2 05-03-2010 07:57 PM
suse 8.1 versus 8.0 vera Linux - Networking 1 06-08-2004 10:00 AM

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

All times are GMT -5. The time now is 02:00 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