1

I'd like to define some global aliases which would be available for everyone on a mult-user linux system (git shortcuts, etc). It seems I have two options avaialable; either place these aliases in (something like) /etc/profile.d/aliases_for_all or editing them into /etc/bash.bashrc.

I like the aliases_for_all approach since I can maintain a single file which doesn't breed .dpkg-* files like a rabbit after applying updates.

Applying changes to /etc/bash.bashrc gets tricky to edit/update at scale -- especially in an environment with multiple distros/versions.

The wrinkle here is that a user can't do a one-shot sudo command using an alias. Given the alias ds="find . -maxdepth 1 -type d -exec du -sh '\''{}'\'' \;", it is available to the initial user login:

$ alias | grep ds
alias ds='find . -maxdepth 1 -type d -exec du -sh '\''{}'\'' \;'

I change to /var and run it via sudo, but it's not there:

$ cd /var
$ sudo ds
sudo: ds: command not found

Oh yeah, sudo resets the environment so maybe a login shell:

$ sudo --login ds
-bash: ds: command not found

Um.. still doesn't work, but alias says it's there:

$ sudo --login alias | grep ds
alias ds='find . -maxdepth 1 -type d -exec du -sh '\''{}'\'' \;'

This is my /etc/sudoers file:

Defaults    env_reset,timestamp_timeout=10
Defaults    mail_badpass
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
root    ALL=(ALL:ALL) ALL

%admin ALL=(ALL) ALL
%sudo   ALL=(ALL:ALL) ALL

..and /etc/sudoers.d/sysadmin_group file (LDAP group which user above is in):

%sysadmin ALL=(ALL) ALL

Maybe I've got something else out of whack here. Should there be a way to get these aliases working with sudo?

1

0

You must log in to answer this question.

Browse other questions tagged .