Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
su - or su root?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
veggie2u
Apprentice
Apprentice


Joined: 16 Oct 2002
Posts: 212
Location: Minneapolis/MN USA

PostPosted: Tue Nov 09, 2004 8:34 pm    Post subject: su - or su root? Reply with quote

What is the best way to assume root privileges? They don't appear to be exactly the same, and I am wondering what the difference is. This came up when I was trying to find out where to put alias' for root in the equivelant of a .bashrc file. What are the locations of the equivalent of a .bashrc file for root when getting there via 'su -' vs 'su root'? And is one of those the same as if you log in as root?
_________________
http://www.cyberward.net
http://www.annieandchris.net
Back to top
View user's profile Send private message
BlackEdder
Advocate
Advocate


Joined: 26 Apr 2004
Posts: 2588
Location: Dutch enclave in Egham, UK

PostPosted: Tue Nov 09, 2004 8:38 pm    Post subject: Reply with quote

I always use su -, because that way it also loads the root path, and you won't have to specify the path to root only commands. I think this is caused because su- also excecuted .bash_profile. The downside is though that you will go to /root
Back to top
View user's profile Send private message
inode77
Veteran
Veteran


Joined: 20 Jan 2004
Posts: 1303
Location: Heart of Europe

PostPosted: Tue Nov 09, 2004 8:38 pm    Post subject: Reply with quote

su => root with user environment
su - => root with root environment
type "export" and compare for example the path once when user and once when root
the location for a root .bashrc would be /root, but since root does not have a bash_profile that will invoke .bashrc you'll have to copy both files from a user skel to get it working.
Back to top
View user's profile Send private message
Dolio
l33t
l33t


Joined: 17 Jun 2002
Posts: 650

PostPosted: Tue Nov 09, 2004 8:43 pm    Post subject: Reply with quote

If you're using sudo (and you should be), there's also the option of

Code:
sudo -s


That gives you a root shell after you type your own password, so you could even disable root login (ala OSX or Ubuntu) and still get a root shell when necessary.

One advantage of sudo is that it uses your own shell and profile. I use zsh, so sudo -s puts me in zsh with my familiar prompt and aliases and stuff, and I don't need to keep the root profile/shell in sync with mine.

The only thing I had to do was add some stuff like:

Code:
if [[ `whoami` == "root" ]]; then
    path=(/sbin /usr/sbin $path)
fi


So that I could get access to an extended command set while I'm root (although some people will tell you that you should type full paths for everything while you're root, just in case).

If you're sticking with su, "su -" should be pretty close to logging in as root. It sources the root profile and moves you to root's home directory, which is often inconvenient for me, because I want to be root in the directory I'm already in.
_________________
They don't have a good bathroom to do coke in.
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20589

PostPosted: Wed Nov 10, 2004 4:28 pm    Post subject: Reply with quote

Moved from Other Things Gentoo.
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum