[HOW TO] skeleton directory /etc/skel?

Hello,


Heineken: Do you want to ensure that all new uers on your computer get the same initial settings?

Tiger: Yes, sometimes I want it. Can you help me?

Heineken: Yup, I'm here to help you :D

Tiger: oh that's sound good. Let's go,

Heineken: Okay buddy,

The (skeleton) /etc/skel directory contains files and folders that will be copied in the new user's home directory (login directory) that when user is created with useradd/adduser command.

root@ubuntu01-virtual-machine:/home/ubuntu01# adduser temp4
Adding user `temp4' ...
Adding new group `temp4' (1003) ...
Adding new user `temp4' (1003) with group `temp4' ...
Creating home directory `/home/temp4' ...

Copying files from `/etc/skel' ...

By default, some configuration files usually place in the /etc/skel:


  • /etc/skel/.bash_logout
  • /etc/skel/.bashrc
  • /etc/skel/.profile
In the position user is deleted, the data inside the /etc/skel remains unchanged.


root@ubuntu01-virtual-machine:~# cd /etc/skel/
root@ubuntu01-virtual-machine:/etc/skel# mkdir heineken
root@ubuntu01-virtual-machine:/etc/skel# useradd -m -d /home/heineken temp3
root@ubuntu01-virtual-machine:/etc/skel# 
root@ubuntu01-virtual-machine:/etc/skel# ls -al /home/heineken/
total 36
drwxr-xr-x 3 temp3 temp3 4096 Th12 23 01:05 .
drwxr-xr-x 5 root  root  4096 Th12 23 01:05 ..
-rw-r--r-- 1 temp3 temp3  220 Th03 30  2013 .bash_logout
-rw-r--r-- 1 temp3 temp3 3637 Th03 30  2013 .bashrc
-rw-r--r-- 1 temp3 temp3 8942 Th04 17  2013 examples.desktop
drwxr-xr-x 2 temp3 temp3 4096 Th12 23 01:05 heineken
-rw-r--r-- 1 temp3 temp3  675 Th03 30  2013 .profile
root@ubuntu01-virtual-machine:/etc/skel# cd /etc/skel/
root@ubuntu01-virtual-machine:/etc/skel# ls
examples.desktop  heineken
root@ubuntu01-virtual-machine:/etc/skel# cd heineken/
root@ubuntu01-virtual-machine:/etc/skel/heineken# touch example
root@ubuntu01-virtual-machine:/etc/skel/heineken# touch example1
root@ubuntu01-virtual-machine:/etc/skel/heineken# ls
example  example1
root@ubuntu01-virtual-machine:/etc/skel/heineken# 
root@ubuntu01-virtual-machine:/etc/skel/heineken# 
root@ubuntu01-virtual-machine:/etc/skel/heineken# passwd temp3
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
root@ubuntu01-virtual-machine:/etc/skel/heineken# 
root@ubuntu01-virtual-machine:/etc/skel/heineken# 
root@ubuntu01-virtual-machine:/etc/skel/heineken# ls -al /home/heineken/
total 36
drwxr-xr-x 3 temp3 temp3 4096 Th12 23 01:05 .
drwxr-xr-x 5 root  root  4096 Th12 23 01:05 ..
-rw-r--r-- 1 temp3 temp3  220 Th03 30  2013 .bash_logout
-rw-r--r-- 1 temp3 temp3 3637 Th03 30  2013 .bashrc
-rw-r--r-- 1 temp3 temp3 8942 Th04 17  2013 examples.desktop
drwxr-xr-x 2 temp3 temp3 4096 Th12 23 01:05 heineken
-rw-r--r-- 1 temp3 temp3  675 Th03 30  2013 .profile


Heineken: Tiger, do you understand?
Tiger: I understand, but .... I want to change the location of /etc/skel. Can you help me?
Heineken: oh cool! I can do it.

You use vi command to edit the /etc/default/useradd

# Default values for useradd(8)
#
# The SHELL variable specifies the default login shell on your
# system.
# Similar to DHSELL in adduser. However, we use "sh" here because
# useradd is a low level utility and should be as general
# as possible
SHELL=/bin/sh
#
# The default group for users
# 100=users on Debian systems
# Same as USERS_GID in adduser
# This argument is used when the -n flag is specified.
# The default behavior (when -n and -g are not specified) is to create a
# primary user group with the same name as the user being added to the
# system.
# GROUP=100
#
# The default home directory. Same as DHOME for adduser
# HOME=/home
#
# The number of days after a password expires until the account
# is permanently disabled
# INACTIVE=-1
#
# The default expire date
# EXPIRE=
#
# The SKEL variable specifies the directory containing "skeletal" user
# files; in other words, files such as a sample .profile that will be
# copied to the new user's home directory when it is created.
# SKEL=/etc/skel
#
# Defines whether the mail spool should be created while
# creating the account

# CREATE_MAIL_SPOOL=yes


Heineken: Tiger, okay, are you ready? If you have any question, please call me via 113 =)))))
Tiger: :D




Thank you for reading this article, please a comment if you are interested.
Tiến Phan - R0039
Knowledge is Endless
Sharing for Success


0 nhận xét:

Post a Comment