Sudo to root, but keep my own aliases?

I have a coworker that has set up some funky aliases in /etc/bash.alias, and he insists on leaving them that way. For example he aliased "ll" to "ls -lahtr", which really bugs me.

Anyway, I was wondering if there were a way for me to sudo to root without reading /etc/bash.alias, or maybe have it re-source my personal .bashrc file after I sudo to root? I have tried adding an alias of my own for sudo="sudo su -;source /home/user/.bashrc", but that doesn't seem to work. Doesn't read anything after the first sudo command.

Is there a good way to do this so I don't have to use the stupid aliases he sets up?

You should read this:
Bash Startup Files (Bash Reference Manual)

There are lots of ways to get the setup you personally require for a bash session. Check out ~./profile -- the last file to be read and executed if it exists. It will override existing aliases with a new alias command. Read the 3 short sections first. Then try a change.

1 Like

sudo ing to root, I find the SUDO_USER=myusername variable in the new environment.
Using your sudo su - , I find

Feb 15 22:52:56 UsersPC sudo:  myusername : TTY=pts/4 ; PWD=/mnt/9 ; USER=root ; COMMAND=/bin/su -

in /var/log/auth.log

echo $BASH_VERSION 
4.4.19(1)-release
2 Likes

First off: if they are his aliases and are not necessary for the working of the system as a whole they have no business being there. They should go to his profile, rc-script or whatever he uses to configure his session. I would make that absolutely clear to him in your position.

This is something that always put me off on Linux systems: instead of putting what is absolutely necessary into the systems configuration and letting everybody take it from there Linux distributions have usually some guy force what he thinks is fine onto the whole world.

Using sudo you can find out "where you came from", that is: which user you used to switch into that UID. This way you could set up some mechanism which one (out of several) configurations to apply, as RudiC already hinted at. (Again: only, if his configuration is not mixed up with the systems configuration, so no putting what belongs to /home/<someuser>/.bashrc into /etc/bashrc (or similarily general configuration scripts.)

Second: you can use the "SETENV:" and "NOSETENV:" directives in /etc/sudoers and their respective commandline equivalents ("-E", etc.) for sudo .

I hope this helps.

bakunin

3 Likes

Thanks! I'll take a look at that.

Thank you, I agree with you. This guy is a special breed, thinks he's gods gift to sys admins. His way or the highway. When I first started my instinct was to fight it. Now I find it just easier to just let his thing, and just find ways around it. I may be putting my foot down on this one though. Thanks for the good info.

--- Post updated at 10:19 AM ---

Thanks, I'll look at that. Much appreciated.

1 Like

Well, challenge him then: if he is not able to find a solution for the problem of separating his environment from the system environment and still get his environment for his own sessions then he is not gods own gift but simply less accomplished to put it in gentle terms. The ancient greeks (sometimes it pays to have endured four years of ancient greek and 6 years of latin in school) had a word for "layman", "private citizen" (as opposed to "office holder") or, generally, "unskilled [one]". You may want to look it up eventually. ;-))

bakunin

2 Likes

Ha, well I actually just told him I was going to change it back, and he just shrugged and let it go. Which is funny because when I talked to him about it the other day he was pretty adamant about leaving it. Anyway, I really didn't want to jump through a bunch of hoops to accomplish it, so it works out that he just let it go.

The funny thing is, he's really not unskilled, he's pretty good at his job, problem is he knows it, and is very condescending and just very short with everyone. Thanks for the suggestions everyone, wish I could say I used them to come up with a cool solution, when really I just needed to deal with the human aspect. :slight_smile: