红联Linux门户
Linux帮助

/etc/skel creates standard files for new users

发布时间:2008-01-18 00:32:53来源:红联作者:Kttlon
The /etc/skel directory contains files and directories that are automatically copied over to a new user's home directory when such user is created by the useradd program.

A home directory, also called a login directory, is the directory on Unix-like operating systems that serves as the repository for a user's personal files, directories and programs, including personal configuration files. It is also the directory that a user is first in after logging into the system. The /etc directory and its subdirectories contain the many important configuration files for the system.

The useradd program is located in the /usr/sbin/ directory, and on most systems it is accessible only by the root (i.e., administrative) user. On some systems this program might be called adduser.

/etc/skel allows a system administrator to create a default home directory for all new users on a computer or network and thus to make certain that all users begin with the same settings or environment.

Several user configuration files are placed in /etc/skel by default when the operating system is installed. Typically they might include .bash_profile, .bashrc, .bash_logout, dircolors, .inputrc and .vimrc. The dots preceding the names of these files indicate that they are hidden files, i.e., files that are not normally visible in order to avoid visual clutter and help reduce the chances of accidental damage.

The contents of /etc/skel can be viewed by using the ls (i.e., list) command with its -a option (which shows all files and directories, including hidden ones), i.e.,

ls -a /etc/skel

The location of /etc/skel can be changed by editing the line that begins with SKEL= in the configuration file /etc/default/useradd. By default this line says SKEL=/etc/skel.

It is usually better to keep /etc/skel as small as possible and put system-wide configuration items into global configuration files such as /etc/profile. This is because the latter makes it much easier to update existing users' files because its settings take effect as soon as the system is turned on and apply to new users and old uses alike.

When a user is removed from the system by an administrator with the userdel command, that user's home directory, including the files and directories that have been copied into it from /etc/skel, remains intact.

The name of the directory skel is derived from the word skeleton, because the files it contains form the basic structure for users' home directories.

===========================================

Using /etc/skel
This tip shows you how to use /etc/skel to ensure that all new users on your system get the same initial settings.

The /etc/skel directory is the directory used by useradd to create the default settings in a new user's home directory.

To change the location of /etc/skel, edit /etc/default/useradd.

Code Listing 1

# useradd defaults file GROUP=100 HOME=/home INACTIVE=-1 EXPIRE= SHELL=/bin/bash SKEL=/etc/skel
Typically files included in /etc/skel are .rc files for shell initialization, but you could also include a public_html directory, a custom dircolors file, or anything else.

Code Listing 2

% ls -A /etc/skel .bash_profile .bashrc .maildir .screenrc .tcsh.config
For more information on customizing /etc/skel see man useradd.

=======================================

A Slackware Desktop Enhancement Guide
Creating a Nominal /etc/skel Directory
© Copyright Darrell Anderson.

Slackware comes packaged with an /etc/skel directory but no files stored within that directory. Many new GNU/Linux users probably cannot appreciate the purpose of this directory until they begin creating new user accounts and initially want to configure all of those accounts in a similar fashion. The /etc/skel directory exists for that purpose.

When adding new user accounts, and if configured properly, the useradd command will copy to the new user’s home directory all files located in the /etc/skel directory. Using this method administrators easily can populate a new user’s home directory with certain files, such as the bash startup files, or basic configuration files.

Enabling this process requires two steps. Step one is to configure the useradd command defaults to use the /etc/skel directory when creating new accounts. By design the /etc/skel directory is where the useradd command will look for files.

Step two is to copy all desired files to the /etc/skel directory.

Like so much with Slackware, creating the initial useradd defaults is a manual but straightforward process. The useradd command comes built with certain defaults. To learn of those defaults, at a command line type useradd -D. The output will look something like this:

GROUP=100
HOME=/home/users
INACTIVE=-1
EXPIRE=
SHELL=
SKEL=/etc/skel

Notice, however, that no default shell is defined. To remedy that problem create the /etc/default/useradd file and supply the desired information. Modified defaults are stored in a text file located at /etc/default/useradd. As is typical with Slackware, this file does not initially exist. Quickly create that file by redirecting the output of useradd -D:

useradd -D > /etc/default/useradd

The format of that file is the same as the console screen output. Edit and save the text file to add a default shell:

GROUP=100
HOME=/home/users
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel

Then populate the /etc/skel directory. Consider a sampling of the files that administrators might want to copy to /etc/skel:

.kde (directory)
.qt (directory)
tmp (directory)
.bash_profile
.bashrc
.bash_logout
.dmrc
.face.icon
.gtkrc-2.0
.hushlogin
.viminfo
.vimrc

Once the /etc/skel directory is populated, and the useradd command is properly configured, adding new user accounts becomes a wee bit less of a chore.

An additional note, Slackware provides a special command line script called adduser that is located in /usr/sbin. Yes, the similarity in names is confusing! The adduser script is basically a front-end to the useradd command. Whenever in doubt about which one to use, however, at the command line type man useradd or man adduser. The script is packaged with no man page.

Lastly, KDE comes packaged with a nice graphical user manager tool called KUser. In most KDE menus the utility is found in the System menu.

Finis
============================================
I don't believe anything should be in skel, users should create their own config files if they want to change any settings. Default settings should be in /etc and (mostly) overrideable by creating config files in the /home/$user directory.

Therefore the only time I modify /etc/skel on new machines is to make life easier, eg. I'll add a public_html directory so that new users know where to put their files. Possibly also an access.log file so they don't get scared when it gets automatically created.

On one multiuser system I have an account on, there are more changes made to /etc/skel. There's a link to documentation, .signature is created with a link to the system's website, and .irssi/config is created to list local irc server and channel .
文章评论

共有 0 条评论