3

Let's say I'm administering an Ubuntu setup with multiple users for my organization.

We have a standard .bash_profile and .bashrc with aliases, prompt settings, PATH declarations, etc... that we want all users to use. When a server is spun up it will be initialized with chef, which will be used to install these dotfiles on the system.

What's the best way to go about doing this? I see a few options, but they all have their downsides -

  1. Install them under /etc (e.g. /etc/profile).Pros: Every user will read from this system-wide location. Cons: It overwrites any existing version of those flies that come pre-installed. We could always copy those into ours to begin with, but then we have to update and maintain them. May not be a problem depending on how often versions of Ubuntu end up changing the default dotfiles

  2. Install them under /etc, but with another names (e.g. /etc/bash_configs) and then append a line to the stock profile and bashrc files to source our new files. Pros: It will also work and our settings will be sources. Cons: Seems really hack, and relies on programmatically appending a line to the end of the stock files to source our additional custom files.

  3. Install them under /etc/skel so that every time a new user is created, those templates will get copied to their home directory. Pros: Each user will get their copy of the files correctly. Cons: What if we update the files, will they get updated in each individual directory? I'm guessing now. It would be better if there a way to symlink the files so all users point to the same files.

I might be over-complicating it, but it just feels like there has to be a cleaner way to do this that I'm missing. I'd be most interested in if there's a way to implement #3 with some sort of auto-update mechanism.

Thanks!

1
  • You can't have an auto update mechanism. That would delete any modifications the users might have made to their local versions.
    – terdon
    Jun 11, 2015 at 23:23

2 Answers 2

2

I think I would go for a mixture of 2 and 3. Place your modified files in /etc/bash_config or wherever. Then, modify the defaults in /etc/skel and have them source the files in /etc/bash_config.

This has some of the advantages of both 2 and 3:

  • New users will have the right files;
  • Any changes will immediately be propagated since the files are being sourced;
  • This allows users to still modify their own dotfiles as they please.
  • It does not involve editing the stock /etc/bash.bashrc or /etc/profile files. This means that upgrades won't break your system.

Note that upgrades modifying the /etc/skel files could cause issues since that would mean your modifications were removed. That shouldn't be a big deal though.

As for its being hacky, well OK, it is. A little. Not too bad though, all you need is to run something like this once:

echo ". /path/to/my_bashrc/" >> /etc/skel/.bashrc
echo ". /path/to/my_profile/" >> /etc/skel/.bashrc
1

Just place you modifications in /etc/profile.d/ with .sh extension (e.g. /etc/profile.d/MYCOMPANY.sh). They will be called by /etc/profile automatically.

This way you can always update and all users will get those updates.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .