Linuxユーザ管理時に考慮する設定(その1 /etc/skel)
/etc/skel
bash関連の設定ファイル(.bashrcと.bash_profile) - tanke25616429のアウトプットで書いたとおり~/.bashrcや~/.bash_profile等は個人ごとに設定できるが、一方で共通の設定を入れておきたいケースがある。また、作成したユーザのホームディレクトリにデフォルトでREADMEを置いておきたいといったケースがあり得る。そういった場合は/etc/skelを利用する。/etc/skel配下に用意したファイルは新規ユーザ作成時にユーザのホームディレクトリに作成される。つまり、/etc/skelはホームディレクトリのデフォルト状態、またはテンプレートのようなものと言える。
/etc/skel配下にREADMEを配置し、.bashrcの内容もカスタマイズする。
[root@nuc-centos8 ~]# echo "Read this!" > /etc/skel/README [root@nuc-centos8 ~]# ls -la /etc/skel/ 合計 28 drwxr-xr-x. 2 root root 76 3月 23 00:47 . drwxr-xr-x. 115 root root 8192 3月 22 00:20 .. -rw-r--r--. 1 root root 18 11月 9 2019 .bash_logout -rw-r--r--. 1 root root 141 11月 9 2019 .bash_profile -rw-r--r--. 1 root root 312 11月 9 2019 .bashrc -rw-r--r--. 1 root root 11 3月 23 00:48 README [root@nuc-centos8 ~]# vi /etc/skel/.bashrc [root@nuc-centos8 ~]# cat /etc/skel/.bashrc # .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # User specific environment PATH="$HOME/.local/bin:$HOME/bin:$PATH" export PATH # Uncomment the following line if you don't like systemctl's auto-paging feature: # export SYSTEMD_PAGER= # User specific aliases and functions echo Welcome alias sl='ls -la'
新たにtestuser3というユーザを作成する。/etc/skelで追加した設定が反映されていることがわかる。
[root@nuc-centos8 ~]# useradd testuser3 [root@nuc-centos8 ~]# su - testuser3 Welcome [testuser3@nuc-centos8 ~]$ ls -la 合計 16 drwx------. 2 testuser3 testuser3 76 3月 23 00:51 . drwxr-xr-x. 10 root root 122 3月 23 00:51 .. -rw-r--r--. 1 testuser3 testuser3 18 11月 9 2019 .bash_logout -rw-r--r--. 1 testuser3 testuser3 141 11月 9 2019 .bash_profile -rw-r--r--. 1 testuser3 testuser3 343 3月 23 00:50 .bashrc -rw-r--r--. 1 testuser3 testuser3 11 3月 23 00:48 README [testuser3@nuc-centos8 ~]$ cat README Read this! [testuser3@nuc-centos8 ~]$ sl / 合計 24 dr-xr-xr-x. 20 root root 271 2月 4 00:45 . dr-xr-xr-x. 20 root root 271 2月 4 00:45 .. drwxrwsr-T. 2 laura accounting 70 1月 13 01:07 accounting lrwxrwxrwx. 1 root root 7 5月 11 2019 bin -> usr/bin dr-xr-xr-x. 7 root root 4096 12月 6 21:58 boot drwxr-xr-x. 21 root root 3520 3月 21 23:28 dev drwxr-xr-x. 115 root root 8192 3月 23 00:51 etc drwxr-xr-x. 3 root root 24 2月 4 00:45 find (略)