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,如需转载请自行联系原作者



相关文章
|
2天前
|
网络协议 Linux 开发工具
Linux中 /etc/sysconfig/network-scripts/ifcfg-<interface> 网络接口配置 详解 看这一篇够用
Linux中 /etc/sysconfig/network-scripts/ifcfg-<interface> 网络接口配置 详解 看这一篇够用
|
2天前
|
存储 移动开发 Linux
Linux系统之部署h5ai目录列表程序
【5月更文挑战第3天】Linux系统之部署h5ai目录列表程序
13 1
|
8天前
|
安全 Linux
【亮剑】如何在Linux使用 chattr 命令更改文件或目录的扩展属性?
【4月更文挑战第30天】`chattr`是Linux中用于管理文件和目录扩展属性的命令,影响文件系统处理方式。常用属性包括:`a`(追加)、`i`(不可变)、`s`(安全删除)和`S`(同步更新)。通过`chattr [选项] <模式> <文件或目录>`设置属性,如`chattr +i <文件名>`使文件不可变,`-i`移除不可变属性。`lsattr`用于查看属性。注意,只有root用户有权更改属性,不是所有文件系统都支持所有属性,且更改关键文件属性前应备份。`chattr`有助于提升系统安全性和数据保护。
|
8天前
|
存储 监控 Linux
【亮剑】Linux中最低调、最易让人忽视的tmp目录,原来用处那么大!
【4月更文挑战第30天】`/tmp`目录在Linux系统中扮演着重要角色,用于存储临时文件,涉及程序运行、系统操作、用户文件及网络通信。它在系统维护、软件开发、数据处理和网络操作等场景中广泛应用。为保障系统稳定和数据安全,需进行权限控制、定期清理、设置磁盘配额、安全审计以及用户教育。理解和管理`/tmp`目录对于优化系统性能和防范风险至关重要。
|
9天前
|
人工智能 Unix Linux
轻松驾驭Linux命令:账户查看、目录文件操作详解
轻松驾驭Linux命令:账户查看、目录文件操作详解
15 1
|
9天前
|
Linux 数据安全/隐私保护
Linux常用命令大全:一杯水时间让你掌握!(附目录和快捷键)(下)
Linux常用命令大全:一杯水时间让你掌握!(附目录和快捷键)
26 2
|
9天前
|
Linux Shell Python
Linux常用命令大全:一杯水时间让你掌握!(附目录和快捷键)(上)
Linux常用命令大全:一杯水时间让你掌握!(附目录和快捷键)
17 2
|
10天前
|
Linux Python
【专栏】Linux 中某个目录中的文件数如何查看?这篇教程分分钟教会你!
【4月更文挑战第28天】在Linux中查看目录文件数的方法包括:使用`ls`结合`wc -l`,如`ls <directory_path> | wc -l`;使用`find`命令,如`find <directory_path> -type f | wc -l`;使用`tree`命令,如`tree <directory_path>`(可能需额外安装);以及通过编程方式,例如Python代码实现。注意权限、效率和选择适用方法以提升操作效率。本文提供了详细步骤和示例,助你轻松掌握!
|
10天前
|
存储 数据挖掘 Linux
【专栏】教你如何快速在 Linux 中找到某个目录中最大的文件
【4月更文挑战第28天】在 Linux 中查找目录中最大文件的方法包括:使用 `du` 结合 `sort`,`find` 结合 `xargs` 和 `sort`,以及编写 Python 脚本。这些技巧适用于服务器管理、数据分析和文件清理等场景,能帮助用户快速定位大文件进行分析、清理或优化。注意文件权限、目录深度和文件系统类型可能影响结果,可结合其他命令增强功能。