I have some aliases and modifications to ls that I'd like available at all times. Is it possible to set environment variables for use when I am logged in as root after I sudo up with sudo su?
| ||||
feedback
|
|
Aside from the fact that sudo su is a terrible idea because it bypasses the auditing that sudo provides, you could do this in one of two ways: either modify root's .profile, which affects all sudo users, or set up a shell script that you run after sudo su to give you the variables and aliases you need. | |||||||
feedback
|
|
There isn't an .profile for only su, but you could write a .profile which detects if you're su'ing. If you are su'd, then "who am i| awk '{print $1}'" will be the user you came from, while "whoami" will be the user you became. If these are different, then you su'd, so do what you need to. | |||||
feedback
|
|
The "su" in the su and sudo commands, although appearing similar, stands for different things. su stands for substitute user, and is more commonly referred to as switch user. sudo stands for super user do, or "do this action as the super user". If you execute a command that's reserved for root by using sudo, your environment (paths, variables, etc) will be used, ie that which is set in /Users/$your_username/.profile file. If you type su, you switch to the root user and can access files and execute binaries limited to this user, but you will do so with your last standard user's environment. If you type su- (note the minus) you will switch to the root user and get his environment. On the Mac the root user, located at /var/root, does NOT have a .profile file. The workaround is to create one (you can copy your user's .profile file), place it in /var/root/, and add any aliases, paths, etc, you need to this file. In order to invoke the file you will need to need to logout as the root user, and re-login again. | |||
|
feedback
|
|
As jRandomUser, typing
(or whatever shell you are using) makes you 'root' with jRandomUser's shell profile. Type
when you're done to dump your privileges and return to working as jRandomUser. Obviously, use with care. My .bashrc sets my prompt to a garish color whenever my UID == 0. | ||||
|
feedback
|
