LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   su versus su - (https://www.linuxquestions.org/questions/linux-newbie-8/su-versus-su-4175499951/)

NotionCommotion 03-30-2014 10:54 AM

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


Madhu Desai 03-30-2014 01:05 PM

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.

NotionCommotion 03-30-2014 01:24 PM

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"?

Madhu Desai 03-30-2014 02:27 PM

Quote:

Originally Posted by NotionCommotion (Post 5136296)
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 (Post 5143717)
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.

NotionCommotion 03-30-2014 02:47 PM

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


All times are GMT -5. The time now is 08:01 PM.