欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

Linux /etc/skel目录

发布时间:2025/3/8 57 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Linux /etc/skel目录 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

  Linux中的/etc/skel目录(skel是skeleton的缩写,意为骨骼、框架。)是用来存放新用户配置文件的目录,当我们添加新用户时,这个目录下的所有文件会自动被复制到新添加的用户的家目录下;默认情况下,/etc/skel目录下的所有文件都是隐藏文件(以.点开头的文件);通过修改、添加、删除/etc/skel目录下的文件,我们可为新创建的用户提供统一、标准的、初始化用户环境。

 

演示:让每个新用户都可以看到hi.txt的文档

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 [root@w ~]# 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 18  2013 .bash_logout -rw-r--r--.  1 root root  176 Jul 18  2013 .bash_profile -rw-r--r--.  1 root root  124 Jul 18  2013 .bashrc [root@w ~]# cd /etc/skel/ [root@w skel]# ll                                        默认查看都是隐藏的 total 0 [root@w skel]# vi hi.txt                                 创建一个hi.txt的文件,写入hello hello [root@w skel]# ll total 4 -rw-r--r--. 1 root root 6 Apr 21 11:22 hi.txt [root@w skel]# useradd test1                             新建test1的用户 [root@w skel]# ll /home/test1/ -al                       查看test1的家目录 total 24 drwx------. 2 test1 test1 4096 Apr 21 11:23 . drwxr-xr-x. 5 root  root  4096 Apr 21 11:23 .. -rw-r--r--. 1 test1 test1   18 Jul 18  2013 .bash_logout -rw-r--r--. 1 test1 test1  176 Jul 18  2013 .bash_profile -rw-r--r--. 1 test1 test1  124 Jul 18  2013 .bashrc -rw-r--r--. 1 test1 test1    6 Apr 21 11:22 hi.txt       看到刚才创建的hi.txt文件 [root@w skel]# cat /home/test1/hi.txt                    可以看到里面的hello内容 hello

模拟删除test1用户/etc/skel/目录下的文件后的恢复

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 删除:/etc/skel/下的文件 [root@w skel]# su - test1 [test1@w ~]$ ls -al total 24 drwx------. 2 test1 test1 4096 Apr 21 11:23 . drwxr-xr-x. 5 root  root  4096 Apr 21 11:23 .. -rw-r--r--. 1 test1 test1   18 Jul 18  2013 .bash_logout -rw-r--r--. 1 test1 test1  176 Jul 18  2013 .bash_profile -rw-r--r--. 1 test1 test1  124 Jul 18  2013 .bashrc -rw-r--r--. 1 test1 test1    6 Apr 21 11:22 hi.txt [test1@w ~]$ rm -f *                               直接删除不管用 [test1@w ~]$ ls -al                                文件还在 total 20 drwx------. 2 test1 test1 4096 Apr 21 11:51 . drwxr-xr-x. 5 root  root  4096 Apr 21 11:23 .. -rw-r--r--. 1 test1 test1   18 Jul 18  2013 .bash_logout -rw-r--r--. 1 test1 test1  176 Jul 18  2013 .bash_profile -rw-r--r--. 1 test1 test1  124 Jul 18  2013 .bashrc [test1@w ~]$ rm -f .*                              删除以.开头的文件 rm: cannot remove `.': Is a directory rm: cannot remove `..': Is a directory [test1@w ~]$ ls -al                                .bash等文件已删除 total 8 drwx------. 2 test1 test1 4096 Apr 21 11:52 . drwxr-xr-x. 5 root  root  4096 Apr 21 11:23 .. [test1@w ~]$ su - test1                            切换到test1用户 Password:  -bash-4.1$                                         出现这种是因为/etc/skel/下的文件没了 -bash-4.1$  -bash-4.1$ logout 恢复/etc/skel/文件 [root@w ~]# cd /etc/skel/                          切换到root,打开/etc/skel/目录 [root@w 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 18  2013 .bash_logout -rw-r--r--.  1 root root  176 Jul 18  2013 .bash_profile -rw-r--r--.  1 root root  124 Jul 18  2013 .bashrc -rw-r--r--.  1 root root    6 Apr 21 11:22 hi.txt [root@w skel]# cp -a .bash* /home/test1/           把所有.bash的文件复制到test1的家目录 [root@w skel]# ll /home/test1/ -al                 查看文件已存在 total 20 drwx------. 2 test1 test1 4096 Apr 21 11:59 . drwxr-xr-x. 5 root  root  4096 Apr 21 11:23 .. -rw-r--r--. 1 root  root    18 Jul 18  2013 .bash_logout        权限只属于root -rw-r--r--. 1 root  root   176 Jul 18  2013 .bash_profile -rw-r--r--. 1 root  root   124 Jul 18  2013 .bashrc [root@w skel]# chown -R test1 /home/test1/         赋于test1用户权限,不赋权不能使用 [root@w skel]# ll /home/test1/ -al               total 20 drwx------. 2 test1 test1 4096 Apr 21 11:59 . drwxr-xr-x. 5 root  root  4096 Apr 21 11:23 .. -rw-r--r--. 1 test1 root    18 Jul 18  2013 .bash_logout        权限赋给test1了 -rw-r--r--. 1 test1 root   176 Jul 18  2013 .bash_profile -rw-r--r--. 1 test1 root   124 Jul 18  2013 .bashrc [root@w skel]# su - test1                          切换到test1用户,已经可以了 [test1@w ~]$  [test1@w ~]$




本文转自cix123  51CTO博客,原文链接:http://blog.51cto.com/zhaodongwei/1766148,如需转载请自行联系原作者


总结

以上是生活随笔为你收集整理的Linux /etc/skel目录的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。