榕叶 发表于 2018-5-20 15:00:26

Linux /etc/skel目录

  Linux中的/etc/skel目录(skel是skeleton的缩写,意为骨骼、框架。)是用来存放新用户配置文件的目录,当我们添加新用户时,这个目录下的所有文件会自动被复制到新添加的用户的家目录下;默认情况下,/etc/skel目录下的所有文件都是隐藏文件(以.点开头的文件);通过修改、添加、删除/etc/skel目录下的文件,我们可为新创建的用户提供统一、标准的、初始化用户环境。
  演示:让每个新用户都可以看到hi.txt的文档
# ll /etc/skel/ -al                            查看/etc/skel/下的文件
total 20
drwxr-xr-x.2 root root 4096 Feb 23 14:39 .
drwxr-xr-x. 59 root root 4096 Apr 19 12:03 ..
-rw-r--r--.1 root root   18 Jul 182013 .bash_logout
-rw-r--r--.1 root root176 Jul 182013 .bash_profile
-rw-r--r--.1 root root124 Jul 182013 .bashrc
# cd /etc/skel/
# ll                                        默认查看都是隐藏的
total 0
# vi hi.txt                                 创建一个hi.txt的文件,写入hello
hello
# ll
total 4
-rw-r--r--. 1 root root 6 Apr 21 11:22 hi.txt
# useradd test1                           新建test1的用户
# ll /home/test1/ -al                     查看test1的家目录
total 24
drwx------. 2 test1 test1 4096 Apr 21 11:23 .
drwxr-xr-x. 5 rootroot4096 Apr 21 11:23 ..
-rw-r--r--. 1 test1 test1   18 Jul 182013 .bash_logout
-rw-r--r--. 1 test1 test1176 Jul 182013 .bash_profile
-rw-r--r--. 1 test1 test1124 Jul 182013 .bashrc
-rw-r--r--. 1 test1 test1    6 Apr 21 11:22 hi.txt       看到刚才创建的hi.txt文件
# cat /home/test1/hi.txt                  可以看到里面的hello内容
hello  模拟删除test1用户/etc/skel/目录下的文件后的恢复
删除:/etc/skel/下的文件
# su - test1
$ ls -al
total 24
drwx------. 2 test1 test1 4096 Apr 21 11:23 .
drwxr-xr-x. 5 rootroot4096 Apr 21 11:23 ..
-rw-r--r--. 1 test1 test1   18 Jul 182013 .bash_logout
-rw-r--r--. 1 test1 test1176 Jul 182013 .bash_profile
-rw-r--r--. 1 test1 test1124 Jul 182013 .bashrc
-rw-r--r--. 1 test1 test1    6 Apr 21 11:22 hi.txt
$ rm -f *                               直接删除不管用
$ ls -al                              文件还在
total 20
drwx------. 2 test1 test1 4096 Apr 21 11:51 .
drwxr-xr-x. 5 rootroot4096 Apr 21 11:23 ..
-rw-r--r--. 1 test1 test1   18 Jul 182013 .bash_logout
-rw-r--r--. 1 test1 test1176 Jul 182013 .bash_profile
-rw-r--r--. 1 test1 test1124 Jul 182013 .bashrc
$ rm -f .*                              删除以.开头的文件
rm: cannot remove `.': Is a directory
rm: cannot remove `..': Is a directory
$ ls -al                              .bash等文件已删除
total 8
drwx------. 2 test1 test1 4096 Apr 21 11:52 .
drwxr-xr-x. 5 rootroot4096 Apr 21 11:23 ..
$ su - test1                            切换到test1用户
Password:
-bash-4.1$                                       出现这种是因为/etc/skel/下的文件没了
-bash-4.1$
-bash-4.1$ logout
恢复/etc/skel/文件
# cd /etc/skel/                        切换到root,打开/etc/skel/目录
# ls -al
total 24
drwxr-xr-x.2 root root 4096 Apr 21 11:22 .
drwxr-xr-x. 59 root root 4096 Apr 21 11:50 ..
-rw-r--r--.1 root root   18 Jul 182013 .bash_logout
-rw-r--r--.1 root root176 Jul 182013 .bash_profile
-rw-r--r--.1 root root124 Jul 182013 .bashrc
-rw-r--r--.1 root root    6 Apr 21 11:22 hi.txt
# cp -a .bash* /home/test1/         把所有.bash的文件复制到test1的家目录
# ll /home/test1/ -al               查看文件已存在
total 20
drwx------. 2 test1 test1 4096 Apr 21 11:59 .
drwxr-xr-x. 5 rootroot4096 Apr 21 11:23 ..
-rw-r--r--. 1 rootroot    18 Jul 182013 .bash_logout      权限只属于root
-rw-r--r--. 1 rootroot   176 Jul 182013 .bash_profile
-rw-r--r--. 1 rootroot   124 Jul 182013 .bashrc
# chown -R test1 /home/test1/         赋于test1用户权限,不赋权不能使用
# ll /home/test1/ -al            
total 20
drwx------. 2 test1 test1 4096 Apr 21 11:59 .
drwxr-xr-x. 5 rootroot4096 Apr 21 11:23 ..
-rw-r--r--. 1 test1 root    18 Jul 182013 .bash_logout      权限赋给test1了
-rw-r--r--. 1 test1 root   176 Jul 182013 .bash_profile
-rw-r--r--. 1 test1 root   124 Jul 182013 .bashrc
# su - test1                        切换到test1用户,已经可以了
$
$  

  学习自:
  老男孩教育
页: [1]
查看完整版本: Linux /etc/skel目录