Which directorys contents are copied to the users home directory upon account creation?

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.

Created June 25, 2005.
Copyright © 2005 The Linux Information Project. All Rights Reserved.

I created some users with:

$ useradd john

and I forgot to specify the parameter -m to create the home directory and to have the skeleton files copied to each user. now I want to do that, and I don't want to recreate all users (there must be an easier way). so, is there any way to create the user directories and copy the skeleton files?

I thought about creating the directories, chowning them to the corresponding user, copying all the skeleton files and chowning them to the corresponding user. but if there's a command like useradd -m that doesn't create the user again, but create the directories, it'd be better.

asked Sep 9, 2009 at 14:33

3

This might sound like a silly idea, but if the users aren't actually doing anything, you could do:

cat /etc/passwd | cut -f 1 -d : >/tmp/users.list

Then edit /tmp/users.list to only contain the users you want. Then do:


for i in `cat /tmp/users.list`
do
    userdel $i
    useradd -m $i
done

However, many Redhat based distributions will create you a new home directory when you first login, providing it is specified in /etc/passwd where the directory should be.

To test that, do an "su - " and see if it does "the right thing". If it doesn't, the above script will work quite nicely, I think.

quanta

50.6k19 gold badges153 silver badges213 bronze badges

answered Sep 9, 2009 at 15:02

dotwaffledotwaffle

6574 silver badges8 bronze badges

7

Also you can use mkhomedir_helper

Usage: /sbin/mkhomedir_helper  [ []]

answered May 17, 2013 at 3:59

Rahul PatilRahul Patil

2,8513 gold badges13 silver badges10 bronze badges

4

You will need to create the users directory manually. This requires three steps:

  1. Create directory in compliance to /etc/passwd, usually there will be already a /home/login entry.
  2. Copy initial files from /etc/skel
  3. And finally set right permissions:

    • mkdir /home/YOU
    • cd /home/YOU
    • cp -r /etc/skel/. .
    • chown -R YOU.YOURGROUP .
    • chmod -R go=u,go-w .
    • chmod go= .

BTW: I always miss the -m option for useradd too. At least Debian based systems should have an adduser command, which I recommend over useradd. If you missed -m option it might also be worth considering to deluser and then recreate the user with proper options.

Edit: Added -r for copying also directories.

answered May 12, 2012 at 16:14

mathmath

4433 silver badges10 bronze badges

7

mkdir -p /home/john
chown john:john /home/john
usermod -d /home/john john

That should do the trick I believe

answered Sep 9, 2009 at 14:49

8

You can use something like pam_mkhomedir to prevent this from ever being an issue with any users in the future. pam_mkhomedir is a PAM module that automatically creates a user's home directory on login if it doesn't exist, and populates it with files from /etc/skel (or whatever skel directory you specify).

This is also a nicely scalable approach because it will continue to solve this problem if you ever switch your user repository over to a directory service like LDAP in the future.

answered May 12, 2012 at 16:29

jgoldschrafejgoldschrafe

4,38518 silver badges18 bronze badges

In my case, the home volume was corrupted and I decided just rebuild it from scratch since not much data involved but I want to keep users' login information, so I recreated the home directories manually with this script:

#!/bin/bash
cat /etc/passwd | while IFS=: read n x i g c d r
do
  # my system has uid started at 1000, but has nfsnobody at 65534:
  if [[ "$i" -ge 1000 && "$i" -le 65000 && ! -x "$d" ]]
  then
    cp -av /etc/skel "$d"
    chown -R "$i:$g" "$d"
    # may needed in SELinux system:
    restorecon -R "$d"
    # add your chmod as your need:
    chmod -R o-rw "$d"
  fi
done

answered Oct 8, 2012 at 16:45

If you edit /etc/login.defs to contain

CREATE_HOME yes

then home directories will be automatically created for any future users, unless you tell the system not to do so.

Another option is to use PAM for logins, and use the pam_mkhomedir module to automagically create the homedir on the first login.

answered Dec 12, 2013 at 8:28

Which directorys contents are copied to the users home directory upon account creation?

Jenny DJenny D

27.4k21 gold badges74 silver badges110 bronze badges

Login with the user john and write from a shell:

xdg-user-dirs-update

That's it! Don't use sudo or su, you don't need root access to create some directories. From a root account, you can use:

sudo -u john xdg-user-dirs-update

That way, you will execute the command as john, that can be useful if you made the mistake with more than one user.

answered Feb 7, 2018 at 19:44

Which directorys contents are copied to the users home directory upon account creation?

My first step after doing a useradd is to su - .

Creates the home directories, copies skeletons, etc - at least on the CentOS 4 box I do that on most frequently.

answered Sep 9, 2009 at 14:35

Which directorys contents are copied to the users home directory upon account creation?

warrenwarren

17.9k23 gold badges82 silver badges134 bronze badges

This is exactly what the mkhomedir_helper $USERNAME command does.

answered Jun 18, 2015 at 8:43

AmandasaurusAmandasaurus

30.4k62 gold badges186 silver badges247 bronze badges

1

You could simply edit /etc/passwd. The second to the last field is the user's home directory.

greeblesnort:x:1000:1000:greeblesnort,,,:/home/greeblesnort:/bin/bash

answered Sep 9, 2009 at 19:19

GreeblesnortGreeblesnort

1,7498 silver badges10 bronze badges

2

usermod -d /home/john john

or

usermod --home /home/john john

and read

man usermod

;)

answered Apr 6, 2015 at 9:23

1

Which directory's contents are copied to the user's home directory upon account creation?

The /etc/skel directory contains files and directories that are automatically copied over to a new user's when it is created from useradd command.

Which directory contains the home directories of all the user accounts in the system?

The /home directory is a place where by default all user home directories are created.

What folder contains the home directories for all user accounts created on the system Linux?

The Unix superuser has access to all directories on the filesystem, and hence can access home directories of all users. The superuser's home directory on older systems was /, but on many newer systems it is located at /root (Linux, BSD), or /var/root (Mac OS X).

What is contained in the home directory?

A home directory is the directory or folder commonly given to a user on a network or Unix or Linux variant operating system. With the home directory the user can store all their personal information, files, login scripts, and user information.