Hack 76. Take Control of New User Setups


configured by default.Whenever you create a new user for your system, Linux
sets up the home directory with a slim pack of default files. These
files are usually located in /etc/skel, the
skeleton directory for all new user homes. This hack explains what
you can and cannot do (easily, anyway) to customize
/etc/skel to fine-tune how a new user home
directory will look and behave.Wouldn't it be nice if you could create a default
configuration for GNOME or KDE, then place all the default
configuration files in /etc/skel so that they
are copied into each new user's directory? Everyone
would start out with the same menus, same wallpaper, etc. Well, dream
on, because although it might not be impossible,
it's nothing close to easy. KDE and GNOME have their
own methods for setting up new users, and neither is careful to make
one user's configuration portable to another.
Usernames and full paths to home directories are littered throughout
the configuration files. So, when you copy them from one home
directory to another, the target user gets a slew of files pointing
to configurations in someone else's inaccessible
home directory. It's a mess.That's why the /etc/skel
directory has so little inside. If you visit the
/etc/skel directory and look at the hidden
files, you'll probably see something such as the
following (if you're lucky, you might find one or
two more files than those listed here):
# ls -a /etc/skel
.alias
.bash_logout
.bash_profile
.bashrc
.cshrc
9.8.1. Improve What Is Already There
If you have fine-tuned your personal settings in one or more of these
files and believe others would benefit from changes you make for your
own personal preferences, edit the existing
/etc/skel to use default settings taken from
your personal settings. Take a look at [Hack #15] . This particular hack
redefines some command aliases so that you can see a color listing of
files in your pager. All it takes is to replace the existing alias
definitions (usually found in .bashrc) to read
something more like this:
alias ls="ls --color"Make those changes in the /etc/skel/.bashrc
alias less="less -R"
file, and all new users will benefit from the hack, assuming your
users are as pleased with the idea as you are.
9.8.2. Create Application Defaults
The /etc/skel directory is also
an ideal place to put customizations for
individual programs, as long as those configuration files do not
include usernames or paths to user directories. It's
quite easy to find out if a file or directory has hardcoded
references to a username or user directory. For example, assuming
your username is carlotta, try this command in
your home directory:
$ grep -r carlotta .kdeYou might be shocked at how many configuration files, among other
things, show up with the username hardcoded. You
can't transfer these files to
/etc/skel and expect them to work for a new
user, because they're filled with references to you
and your home directory.But if you run the same test on another configuration file or
directory and your username never shows up, there's
hope that you can use the configuration in the
/etc/skel directory.One good candidate for placement in /etc/skel is
the .Xdefaults file ( [Hack #50] gives examples of the
benefits you can reap by customizing this file). You can set up an
improved look and feel for a number of X terminals once, place it in
/etc/skel, and every new user will automatically
benefit from those customizations.You might also want to customize the command-line prompt in the
/etc/skel directory, assuming you think everyone
will like a custom prompt [Hack #13] .
9.8.3. Be Selfish
Not all the changes you make will be for the benefit of new users.
For example, I use a character-mode editor called
joe in part because I have made major
modifications to the key assignments so that the editor behaves
exactly the way I like it. All the settings are in the file
~/.joerc.When I create a new user, I log in as the new user and run
joe to make some final adjustments to the files.
Naturally, nothing works in the editor the way I expect it to work.
because this new user's home directory does not have
my .joerc configuration file.
It's possible to make a copy, but that involves
logging back in as root and changing ownershipwhich involves
more work than it should. So, for my benefit as an administrator, I
have placed a copy of my .joerc file in the
/etc/skel directory so that
joe works the way I expect it to work every time
I create a new user account and log in as that user.
9.8.4. Default Desktop Environments
I have had some limited success at
setting up a very basic user configuration from scratch, and then
copying the user's .kde
directory into /etc/skel so that it becomes the
default for new users. The one catch is that KDE usually puts the
username in the ~/.kde/share/config/ksmserverrc
file. You can delete the line containing the username, which might or
might not make it possible to use /etc/skel/.kde
as a default configuration. Sometimes it works, sometimes it
doesn't. If you can't blame it on
different Linux distributions, maybe it's sunspots.Another thing you can do is create a default
Desktop directory, with various desktop icons.
But even in this case you have to be cautious. because some desktop
environments might still detect that the new users are starting
GNOME, KDE, or whatever for the first time, and override your desktop
configuration by creating their own idea of what a default desktop
should look like.One sure bet is not to bother trying to create a default
configuration in /etc/skel with GNOME. GNOME
sets up a number of default directories, and launches a settings
daemon called gconfd, which remembers settings
and even rewrites them to your home directory if you delete them
manually. If there's a way to set up a skeleton
version of GNOME in /etc/skel that can be copied
to new user home directories, either a lot of hard work or a lot of
magic must be involved.