目的
/etc/skel/
目錄是用來存放新使用者配置檔案的目錄,當新增新使用者(useradd
)的時候,這個目錄下的所有檔案會自動被複制到新新增的使用者的家目錄下。執行下面指令查看/etc/skel
ls -la /etc/skel/
ls
所包含的命令:
-a 列出隱藏檔
-l 列表方式顯示檔案 輸出結果:
drwxr-xr-x 2 root root 4096 Aug 24 09:03 . drwxr-xr-x 96 root root 4096 Jul 25 10:34 .. -rw-r--r-- 1 root root 220 Apr 18 2019 .bash_logout -rw-r--r-- 1 root root 3523 Jan 11 2021 .bashrc -rw-r--r-- 1 root root 1010 Aug 24 09:03 .profile
指定 skel
新增使用者時可以透過命令來改變預設的/etc/skel
目錄作為使用者配置檔案的目錄:
sudo useradd -d /home/jasonchen -m -k /etc/my_skel jasonchen
變更預設 skel
不想在每次新建使用者時,都重新指定新的使用者配置檔案的目錄,可以通過修改/etc/default/useradd
配置檔案並查詢SKEL變數的定義:
# 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/bash # # 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
如果此變數的定義已被註釋掉,可以取消註釋,然後修改其值:
SKEL=/etc/my_skel
The post Linux /etc/skel 目錄 appeared first on 可丁丹尼 @ 一路往前走2.0.