加入收藏 | 设为首页 | 会员中心 | 我要投稿 拼字网 - 核心网 (https://www.hexinwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Unix > 正文

Linux /etc/skel目录

发布时间:2022-10-25 14:03:02 所属栏目:Unix 来源:转载
导读: Linux中的/etc/skel目录(skel是skeleton的缩写unix系统文件,意为骨骼、框架。)是用来存放新用户配置文件的目录,当我们添加新用户时,这个目录下的所有文件会自动被复制到新添加的用户的

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

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

[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/目录下的文件后的恢复

删除:/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?~]$

学习自:

老男孩教育

(编辑:拼字网 - 核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章