美文网首页
文件和目录权限说明

文件和目录权限说明

作者: 小屁孩云熙 | 来源:发表于2021-10-11 19:09 被阅读0次

1. 文件信息

r   可以读文件的内容
w   可以编辑文件的内容
x   执行这个文件(脚本)

1.1 实验环境

1.1.1 无任何权限

[root@sec tmp]# ll
total 8
----------. 1 root    root    70 Oct 11 13:31 yunxuan_root.txt
----------. 1 yunxuan yunxuan 73 Oct 11 13:32 yunxuan.txt
yunxuan_root.txt(无任何权限) yunxuan.txt(无任何权限)
root 可读写 可读写
yunxuan 可写,写入内容覆盖原有文件内容
admin
  • root 用户操作 yunxuan_root.txt 文件
# (可读写)
[root@sec tmp]# cat yunxuan_root.txt 
123456
[root@sec tmp]# echo "echo helloroot" > yunxuan_root.txt 
[root@sec tmp]# cat yunxuan_root.txt
echo helloroot
[root@sec tmp]# ./yunxuan_root.txt
-bash: ./yunxuan_root.txt: Permission denied
  • root 用户操作 yunxuan.txt 文件
# (可读写)
[root@sec tmp]# cat yunxuan.txt
yunxuan
[root@sec tmp]# echo "echo helloroot" > yunxuan.txt
[root@sec tmp]# cat yunxuan.txt 
echo helloroot
[root@sec tmp]# ./yunxuan.txt
-bash: ./yunxuan.txt: Permission denied
  • yunxuan 用户操作 yunxuan_root.txt 文件
# (无任何权限)
[yunxuan@sec tmp]$ cat yunxuan_root.txt 
cat: yunxuan_root.txt: Permission denied
[yunxuan@sec tmp]$ echo "echo helloyunxuan" >> yunxuan_root.txt
-bash: yunxuan_root.txt: Permission denied
[yunxuan@sec tmp]$ ./yunxuan_root.txt
-bash: ./yunxuan_root.txt: Permission denied
  • yunxuan 用户操作 yunxuan.txt 文件
# (可写,覆盖文件原有内容)
[yunxuan@sec tmp]$ cat yunxuan.txt 
cat: yunxuan.txt: Permission denied
[yunxuan@sec tmp]$ echo "123" >> yunxuan.txt
-bash: yunxuan.txt: Permission denied
[yunxuan@sec tmp]$ vim yunxuan.txt
[yunxuan@sec tmp]$ ./yunxuan.txt
-bash: ./yunxuan.txt: Permission denied
[root@sec tmp]# cat yunxuan.txt 
echo helloyunxuan01
123456
  • admin 用户操作 yunxuan_root.txt 文件
# (无任何权限)
[admin@sec tmp]$ cat yunxuan_root.txt 
cat: yunxuan_root.txt: Permission denied
[admin@sec tmp]$ echo "echo helloadmin" > yunxuan_root.txt
-bash: yunxuan_root.txt: Permission denied
[admin@sec tmp]$ ./yunxuan_root.txt
-bash: ./yunxuan_root.txt: Permission denied
  • admin 用户操作 yunxuan.txt 文件
[admin@sec tmp]$ cat yunxuan.txt
cat: yunxuan.txt: Permission denied
[admin@sec tmp]$ echo "echo helloadmin" > yunxuan.txt
-bash: yunxuan.txt: Permission denied
[admin@sec tmp]$ ./yunxuan.txt
-bash: ./yunxuan.txt: Permission denied

1.1.2 有读权限

[root@sec tmp]# ll
total 8
-r--r--r--. 1 root    root 14 Oct 11 12:50 yunxuan_root.txt
-r--r--r--. 1 yunxuan root 14 Oct 11 13:00 yunxuan.txt
yunxuan_root.txt(读权限) yunxuan.txt(读权限)
root 可读写 可读写
yunxuan 可读 可读写
admin 可读 可读
  • root 用户操作 yunxuan_root.txt 文件
# (可读写)
[root@sec tmp]# cat yunxuan_root.txt 
echo helloroot
[root@sec tmp]# echo "echo helloroot01" >> yunxuan_root.txt
[root@sec tmp]# cat yunxuan_root.txt
echo helloroot
echo helloroot01
[root@sec tmp]# ./yunxuan_root.txt
-bash: ./yunxuan_root.txt: Permission denied
  • root 用户操作 yunxuan.txt 文件
# (可读写)
[root@sec tmp]# cat yunxuan.txt 
echo helloyunxuan01
123456
[root@sec tmp]# echo "echo helloroot" >> yunxuan.txt
[root@sec tmp]# cat yunxuan.txt
echo helloyunxuan01
123456
echo helloroot
[root@sec tmp]# ./yunxuan.txt
-bash: ./yunxuan.txt: Permission denied
  • yunxuan 用户操作 yunxuan_root.txt 文件
# (可读)
[yunxuan@sec tmp]$ cat yunxuan_root.txt 
echo helloroot
echo helloroot01
[yunxuan@sec tmp]$ echo "echo helloyunxuan" >> yunxuan_root.txt
-bash: yunxuan_root.txt: Permission denied
[yunxuan@sec tmp]$ vim yunxuan_root.txt
[yunxuan@sec tmp]$ ./yunxuan_root.txt
-bash: ./yunxuan_root.txt: Permission denied
  • yunxuan 用户操作 yunxuan.txt 文件
# (可读写)
[yunxuan@sec tmp]$ cat yunxuan.txt 
echo helloyunxuan01
123456
echo helloroot
[yunxuan@sec tmp]$ echo "echo helloyunxuan" >> yunxuan.txt
-bash: yunxuan.txt: Permission denied
[yunxuan@sec tmp]$ vim yunxuan.txt
[yunxuan@sec tmp]$ ./yunxuan.txt
-bash: ./yunxuan.txt: Permission denied
[root@sec tmp]# cat yunxuan.txt 
echo helloyunxuan01
123456
echo helloroot
echo helloyunxuan
  • admin 用户操作 yunxuan_root.txt 文件
# (可读)
[admin@sec tmp]$ cat yunxuan_root.txt 
echo helloroot
echo helloroot01
[admin@sec tmp]$ echo "echo helloadmin" >> yunxuan_root.txt
-bash: yunxuan_root.txt: Permission denied
[admin@sec tmp]$ ./yunxuan_root.txt
-bash: ./yunxuan_root.txt: Permission denied
  • admin 用户操作 yunxuan.txt 文件
[admin@sec tmp]$ cat yunxuan.txt 
echo helloyunxuan01
123456
echo helloroot
echo helloyunxuan
[admin@sec tmp]$ echo "echo helloadmin" >> yunxuan.txt
-bash: yunxuan.txt: Permission denied
[admin@sec tmp]$ ./yunxuan.txt
-bash: ./yunxuan.txt: Permission denied

1.1.3 有写权限

[root@sec tmp]# ll
total 8
--w--w--w-. 1 root    root 15 Oct 11 13:10 yunxuan_root.txt
--w--w--w-. 1 yunxuan root 18 Oct 11 13:14 yunxuan.txt
yunxuan_root.txt(有写权限) yunxuan.txt(有写权限)
root 可读写 可读写
yunxuan 可写 可写
admin 可写 可写
  • root 用户操作 yunxuan_root.txt 文件
# (可读写)
[root@sec tmp]# cat yunxuan_root.txt 
echo helloroot
echo helloroot01
[root@sec tmp]# echo "echo helloroot02" >> yunxuan_root.txt
[root@sec tmp]# ./yunxuan_root.txt
-bash: ./yunxuan_root.txt: Permission denied
  • root 用户操作 yunxuan.txt 文件
# (可读写)
[root@sec tmp]# cat yunxuan.txt 
echo helloyunxuan01
123456
echo helloroot
echo helloyunxuan
[root@sec tmp]# echo "echo helloroot" >> yunxuan.txt
[root@sec tmp]# cat yunxuan.txt
echo helloyunxuan01
123456
echo helloroot
echo helloyunxuan
echo helloroot
[root@sec tmp]# ./yunxuan.txt
-bash: ./yunxuan.txt: Permission denied
  • yunxuan 用户操作 yunxuan_root.txt 文件
# (可写)
[yunxuan@sec tmp]$ cat yunxuan_root.txt 
cat: yunxuan_root.txt: Permission denied
[yunxuan@sec tmp]$ echo "echo helloyunxuan001" > yunxuan_root.txt
[yunxuan@sec tmp]$ ./yunxuan_root.txt
-bash: ./yunxuan_root.txt: Permission denied
[root@sec tmp]# cat yunxuan_root.txt 
echo helloyunxuan001
  • yunxuan 用户操作 yunxuan.txt 文件
# (可写)
[yunxuan@sec tmp]$ cat yunxuan.txt 
cat: yunxuan.txt: Permission denied
[yunxuan@sec tmp]$ echo "echo helloyunxuan001" > yunxuan.txt
[yunxuan@sec tmp]$ ./yunxuan.txt
-bash: ./yunxuan.txt: Permission denied
[root@sec tmp]# cat yunxuan.txt 
echo helloyunxuan001
  • admin 用户操作 yunxuan_root.txt 文件
# (可写)
[admin@sec tmp]$ cat yunxuan_root.txt 
cat: yunxuan_root.txt: Permission denied
[admin@sec tmp]$ echo "echo helloadmin" > yunxuan_root.txt
[admin@sec tmp]$ ./yunxuan_root.txt
-bash: ./yunxuan_root.txt: Permission denied
[root@sec tmp]# cat yunxuan_root.txt 
echo helloadmin
  • admin 用户操作 yunxuan.txt 文件
# (可写)
[admin@sec tmp]$ cat yunxuan.txt 
cat: yunxuan.txt: Permission denied
[admin@sec tmp]$ echo "echo helloadmin" > yunxuan.txt 
[admin@sec tmp]$ ./yunxuan.txt
-bash: ./yunxuan.txt: Permission denied
[root@sec tmp]# cat yunxuan.txt 
echo helloadmin

1.1.4 有执行权限

[root@sec tmp]# ll
total 8
---x--x--x. 1 root    root    16 Oct 11 14:46 yunxuan_root.txt
---x--x--x. 1 yunxuan yunxuan 16 Oct 11 14:47 yunxuan.txt
yunxuan_root.txt(只有执行权限) yunxuan.txt(只有执行权限)
root 读写执行 读写执行
yunxuan 可写(覆盖原有文件内容)
admin
  • root 用户操作 yunxuan_root.txt 文件
# (读写执行)
[root@sec tmp]# cat yunxuan_root.txt 
echo helloadmin
[root@sec tmp]# echo "echo helloroot001" > yunxuan_root.txt
[root@sec tmp]# cat yunxuan_root.txt
echo helloroot001
[root@sec tmp]# ./yunxuan_root.txt
helloroot001
  • root 用户操作 yunxuan.txt 文件
# (读写执行)
[root@sec tmp]# cat yunxuan.txt 
echo helloadmin
[root@sec tmp]# echo "echo helloroot001" > yunxuan.txt 
[root@sec tmp]# cat yunxuan.txt
echo helloroot001
[root@sec tmp]# ./yunxuan.txt
helloroot001
  • yunxuan 用户操作 yunxuan_root.txt 文件
# (无任何权限)
[yunxuan@sec tmp]$ cat yunxuan_root.txt 
cat: yunxuan_root.txt: Permission denied
[yunxuan@sec tmp]$ echo "123" >> yunxuan_root.txt
-bash: yunxuan_root.txt: Permission denied
[yunxuan@sec tmp]$ vim yunxuan_root.txt
[yunxuan@sec tmp]$ ./yunxuan_root.txt
bash: ./yunxuan_root.txt: Permission denied
  • yunxuan 用户操作 yunxuan.txt 文件
# (可写,覆盖原有文件内容)
[yunxuan@sec tmp]$ cat yunxuan.txt 
cat: yunxuan.txt: Permission denied
[yunxuan@sec tmp]$ echo "123" >> yunxuan.txt
-bash: yunxuan.txt: Permission denied
[yunxuan@sec tmp]$ vim yunxuan.txt
[yunxuan@sec tmp]$ ./yunxuan.txt
bash: ./yunxuan.txt: Permission denied
[root@sec tmp]# cat yunxuan.txt 
echo 123
  • admin 用户操作 yunxuan_root.txt 文件
# (无任何权限)
[admin@sec tmp]$ cat yunxuan_root.txt 
cat: yunxuan_root.txt: Permission denied
[admin@sec tmp]$ echo "123" > yunxuan_root.txt
-bash: yunxuan_root.txt: Permission denied
[admin@sec tmp]$ ./yunxuan_root.txt
bash: ./yunxuan_root.txt: Permission denied
  • admin 用户操作 yunxuan.txt 文件
# (无任何权限)
[admin@sec tmp]$ cat yunxuan.txt 
cat: yunxuan.txt: Permission denied
[admin@sec tmp]$ echo "123" > yunxuan.txt
-bash: yunxuan.txt: Permission denied
[admin@sec tmp]$ ./yunxuan.txt
bash: ./yunxuan.txt: Permission denied

1.2 文件权限配置的结论

  1. root 用户对所有文件有绝对的权限,只要有了执行权限,root 用户可以无敌存在。
  2. 对于文件来说,写的权限和执行的权限,都要需要读权限配合
  3. 如果想对文件进行操作,必须对文件赋予读的权限
  4. 一般普通文件,默认文件644,保证属主用户对文件可以编辑,保证其他用户可以读取文件内容

2. 目录信息

r   读目录中的文件属性信息
w   可以在目录中添加或删除文件数据信息
x   是否可以进入到目录中

2.1 实验环境

2.1.1 无任何权限

[root@sec tmp]# ll
total 0
d---------. 2 yunxuan yunxuan 6 Oct 11 15:35 yunxuan
d---------. 2 root    root    6 Oct 11 15:35 yunxuan_root
yunxuan_root(无任何权限) yunxuan(无任何权限)
root 读写执行 读写执行
yunxuan 无任何权限 无任何权限
admin 无任何权限 无任何权限
  • root 用户操作 yunxuan_root 目录
# (读写执行)
[root@sec tmp]# ll yunxuan_root/
total 0
[root@sec tmp]# touch yunxuan_root/root.txt
[root@sec tmp]# ll yunxuan_root/
total 0
-rw-r--r--. 1 root root 0 Oct 11 15:41 root.txt
[root@sec tmp]# cd yunxuan_root/
[root@sec yunxuan_root]# ll
total 0
-rw-r--r--. 1 root root 0 Oct 11 15:41 root.txt
  • root 用户操作 yunxuan 目录
# (读写执行)
[root@sec tmp]# ll yunxuan
total 0
[root@sec tmp]# touch yunxuan/root.txt
[root@sec tmp]# ll yunxuan/
total 0
-rw-r--r--. 1 root root 0 Oct 11 15:43 root.txt
[root@sec tmp]# cd yunxuan
[root@sec yunxuan]# ll
total 0
-rw-r--r--. 1 root root 0 Oct 11 15:43 root.txt

  • yunxuan 用户操作 yunxuan_root 目录
# (无任何权限)
[yunxuan@sec tmp]$ ll yunxuan_root/
ls: cannot open directory yunxuan_root/: Permission denied
[yunxuan@sec tmp]$ touch yunxuan_root/yunxuan.txt
touch: cannot touch ‘yunxuan_root/yunxuan.txt’: Permission denied
[yunxuan@sec tmp]$ cd yunxuan_root/
-bash: cd: yunxuan_root/: Permission denied
  • yunxuan 用户操作 yunxuan 目录
# (无任何权限)
[yunxuan@sec tmp]$ ll yunxuan
ls: cannot open directory yunxuan: Permission denied
[yunxuan@sec tmp]$ touch yunxuan/yunxuan.txt
touch: cannot touch ‘yunxuan/yunxuan.txt’: Permission denied
[yunxuan@sec tmp]$ cd yunxuan
-bash: cd: yunxuan: Permission denied
  • admin 用户操作 yunxuan_root 目录
# (无任何权限)
[admin@sec tmp]$ ll yunxuan_root/
ls: cannot open directory yunxuan_root/: Permission denied
[admin@sec tmp]$ touch yunxuan_root/admin.txt
touch: cannot touch ‘yunxuan_root/admin.txt’: Permission denied
[admin@sec tmp]$ cd yunxuan_root/
-bash: cd: yunxuan_root/: Permission denied
  • admin 用户操作 yunxuan 目录
# (无任何权限)
[admin@sec tmp]$ ll yunxuan
ls: cannot open directory yunxuan: Permission denied
[admin@sec tmp]$ touch yunxuan/admin.txt
touch: cannot touch ‘yunxuan/admin.txt’: Permission denied
[admin@sec tmp]$ cd yunxuan
-bash: cd: yunxuan: Permission denied

2.1.2 有读权限

[root@sec tmp]# ll
total 0
dr--r--r--. 2 yunxuan yunxuan 22 Oct 11 15:43 yunxuan
dr--r--r--. 2 root    root    22 Oct 11 15:41 yunxuan_root
yunxuan_root(有读权限) yunxuan(有读权限)
root 读写执行 读写执行
yunxuan 可读部分信息 可读部分信息
admin 可读部分信息 可读部分信息
  • yunxuan 用户操作 yunxuan_root 目录
# (可读部分信息)
[yunxuan@sec tmp]$ ll yunxuan_root/
ls: cannot access yunxuan_root/root.txt: Permission denied
total 0
-????????? ? ? ? ?            ? root.txt
[yunxuan@sec tmp]$ touch yunxuan_root/yunxuan.txt
touch: cannot touch ‘yunxuan_root/yunxuan.txt’: Permission denied
[yunxuan@sec tmp]$ cd yunxuan_root/
-bash: cd: yunxuan_root/: Permission denied
  • yunxuan 用户操作 yunxuan 目录
# (可读部分信息)
[yunxuan@sec tmp]$ ll yunxuan
ls: cannot access yunxuan/root.txt: Permission denied
total 0
-????????? ? ? ? ?            ? root.txt
[yunxuan@sec tmp]$ touch yunxuan/yunxuan.txt
touch: cannot touch ‘yunxuan/yunxuan.txt’: Permission denied
[yunxuan@sec tmp]$ cd yunxuan
-bash: cd: yunxuan: Permission denied
  • admin 用户操纵 yunxuan_root 目录
# (可读部分信息)
[admin@sec tmp]$ ll yunxuan_root
ls: cannot access yunxuan_root/root.txt: Permission denied
total 0
-????????? ? ? ? ?            ? root.txt
[admin@sec tmp]$ touch yunxuan_root/admin.txt
touch: cannot touch ‘yunxuan_root/admin.txt’: Permission denied
[admin@sec tmp]$ cd yunxuan_root
-bash: cd: yunxuan_root: Permission denied
  • admin 用户操作 yunxuan 目录
# (可读部分信息)
[admin@sec tmp]$ ll yunxuan
ls: cannot access yunxuan/root.txt: Permission denied
total 0
-????????? ? ? ? ?            ? root.txt
[admin@sec tmp]$ touch yunxuan/yunxuan.txt
touch: cannot touch ‘yunxuan/yunxuan.txt’: Permission denied
[admin@sec tmp]$ cd yunxuan
-bash: cd: yunxuan: Permission denied

2.1.3 有写权限

[root@sec tmp]# ll
total 0
d-w--w--w-. 2 yunxuan yunxuan 22 Oct 11 15:43 yunxuan
d-w--w--w-. 2 root    root    22 Oct 11 15:57 yunxuan_root
yunxuan_root(有写权限) yunxuan(有写权限)
root 读写执行 读写执行
yunxuan 无任何权限 无任何权限
admin
  • yunxuan 用户操作 yunxuan_root 目录
# (无任何权限)
[yunxuan@sec tmp]$ ll yunxuan_root
ls: cannot open directory yunxuan_root: Permission denied
[yunxuan@sec tmp]$ touch yunxuan_root/yunxuan.txt
touch: cannot touch ‘yunxuan_root/yunxuan.txt’: Permission denied
[yunxuan@sec tmp]$ cd yunxuan_root
-bash: cd: yunxuan_root: Permission denied
  • yunxuan 用户操作 yunxuan 目录
# (无任何权限)
[yunxuan@sec tmp]$ ll yunxuan
ls: cannot open directory yunxuan: Permission denied
[yunxuan@sec tmp]$ touch yunxuan/yunxuan.txt
touch: cannot touch ‘yunxuan/yunxuan.txt’: Permission denied
[yunxuan@sec tmp]$ cd yunxuan
-bash: cd: yunxuan: Permission denied
  • admin 用户操作 yunxuan_root 目录
# (无任何权限)
[admin@sec tmp]$ ll yunxuan_root
ls: cannot open directory yunxuan_root: Permission denied
[admin@sec tmp]$ touch yunxuan_root/admin.txt
touch: cannot touch ‘yunxuan_root/admin.txt’: Permission denied
[admin@sec tmp]$ cd yunxuan_root
-bash: cd: yunxuan_root: Permission denied
  • admin 用户操作 yunxuan 目录
# (无任何权限)
[admin@sec tmp]$ ll yunxuan
ls: cannot open directory yunxuan: Permission denied
[admin@sec tmp]$ touch yunxuan/admin.txt
touch: cannot touch ‘yunxuan/admin.txt’: Permission denied
[admin@sec tmp]$ cd yunxuan
-bash: cd: yunxuan: Permission denied

2.1.4 有执行权限

[root@sec tmp]# ll
total 0
d--x--x--x. 2 yunxuan yunxuan 22 Oct 11 15:43 yunxuan
d--x--x--x. 2 root    root    22 Oct 11 15:57 yunxuan_root
yunxuan_root(有执行权限) yunxuan(有执行权限)
root 读写执行 读写执行
yunxuan 执行(进入目录) 执行(进入目录)
admin 执行(进入目录) 执行(进入目录)
  • yunxuan 用户操作 yunxuan_root 目录
# (可切换目录)
[yunxuan@sec tmp]$ ll yunxuan_root/
ls: cannot open directory yunxuan_root/: Permission denied
[yunxuan@sec tmp]$ touch yunxuan_root/yunxuan.txt
touch: cannot touch ‘yunxuan_root/yunxuan.txt’: Permission denied
[yunxuan@sec tmp]$ cd yunxuan_root/
[yunxuan@sec yunxuan_root]$ ll
ls: cannot open directory .: Permission denied
  • yunxuan 用户操做 yunxuan 目录
# (可切换目录)
[yunxuan@sec tmp]$ ll yunxuan
ls: cannot open directory yunxuan: Permission denied
[yunxuan@sec tmp]$ touch yunxuan/yunxuan.txt
touch: cannot touch ‘yunxuan/yunxuan.txt’: Permission denied
[yunxuan@sec tmp]$ cd yunxuan
[yunxuan@sec yunxuan]$ ls
ls: cannot open directory .: Permission denied
  • admin 用户操作 yunxuan_root 目录
# (可切换目录)
[admin@sec tmp]$ ll yunxuan_root/
ls: cannot open directory yunxuan_root/: Permission denied
[admin@sec tmp]$ touch yunxuan_root/admin.txt
touch: cannot touch ‘yunxuan_root/admin.txt’: Permission denied
[admin@sec tmp]$ cd yunxuan_root/
[admin@sec yunxuan_root]$ ls
ls: cannot open directory .: Permission denied
  • admin 用户操作 yunxuan 目录
# (可切换目录)
[admin@sec tmp]$ ll yunxuan
ls: cannot open directory yunxuan: Permission denied
[admin@sec tmp]$ touch yunxuan/admin.txt
touch: cannot touch ‘yunxuan/admin.txt’: Permission denied
[admin@sec tmp]$ cd yunxuan
[admin@sec yunxuan]$ ls
ls: cannot open directory .: Permission denied

2.2 目录权限配置的结论

  1. root 用户对目录信息有绝对权限
  2. 对于目录来说,写的权限和读权限,都需要执行权限配合
  3. 如果想对目录进行操作,必须对目录赋予执行权限
  4. 一个目录文件默认权限为755,保证属主用户对目录进行编辑,保证其他用户可以读物目录中的信息,可以进入到目录中。

2.3 问题解答

[root@sec tmp]# ll
total 0
dr--r--r--. 2 yunxuan yunxuan 22 Oct 11 15:43 yunxuan
dr--r--r--. 2 root    root    22 Oct 11 15:41 yunxuan_root
[yunxuan@sec tmp]$ ll yunxuan
ls: cannot access yunxuan/root.txt: Permission denied
total 0
-????????? ? ? ? ?            ? root.txt

原因分析:

  1. 文件名保存在上级目录的 block 中
  2. 文件的属性信息保存在文件的 inode 中
  3. yunxuan 用户无法进入 yunxuan 目录中,因此无法查看 root.txt 的文件属性信息,只能查看文件名。

2.4 umask值

umask 默认为 0022

可以空控制文件和目录的默认权限

2.4.1 修改umask后

默认文件权限:666 - 022 = 644
umask数值是奇数:666 - 033 = 633 + 011 = 644
umask数值是偶数:666 - 022 = 644
[root@sec files]# umask
0022
[root@sec files]# touch yunxuan.txt
[root@sec files]# ll
total 0
-rw-r--r--. 1 root root 0 Oct 11 17:42 yunxuan.txt
[root@sec files]# umask 033
[root@sec files]# umask
0033
[root@sec files]# touch yunxuan01
[root@sec files]# ll
total 0
-rw-r--r--. 1 root root 0 Oct 11 17:42 yunxuan01
-rw-r--r--. 1 root root 0 Oct 11 17:42 yunxuan.txt
默认目录权限:777 - 022 = 755
umask值为奇数:777 - 033 = 744
umask值为偶数:777 - 022 = 755
[root@sec files]# umask
0022
[root@sec files]# mkdir yunxuan
[root@sec files]# ll
total 0
drwxr-xr-x. 2 root root 6 Oct 11 17:43 yunxuan
[root@sec files]# umask 033
[root@sec files]# mkdir yunxuan01
[root@sec files]# ll
total 0
drwxr-xr-x. 2 root root 6 Oct 11 17:43 yunxuan
drwxr--r--. 2 root root 6 Oct 11 17:43 yunxuan01

2.4.2 永久修改umask

vim /etc/profile
image-20211012130015907.png
# 内容解释
$UID                -- 显示当前用户的 uid
/usr/bin/id -gn     -- 显示当前用户的组名
/usr/bin/id -un     -- 显示当前的用户名
[yunxuan@sec ~]$ id
uid=1000(yunxuan) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[yunxuan@sec ~]$ /usr/bin/id -gn
root
[yunxuan@sec ~]$ /usr/bin/id -un
yunxuan

2.4.3 扩展-判断比较符号

-gt     -- 大于
-lt     -- 小于
-eq     -- 等于
-ge     -- 大于等于
-le     -- 小于等于
-ne     -- 不等于

3. 特殊目录 /etc/skel

创建用户时,参考该目录,在新用户的家目录下创建以下文件。

[root@sec ~]# cd /etc/skel/
[root@sec skel]# ll -a
total 24
drwxr-xr-x.  2 root root   62 Apr 11  2018 .
drwxr-xr-x. 77 root root 8192 Oct 11 17:47 ..
-rw-r--r--.  1 root root   18 Oct 31  2018 .bash_logout
-rw-r--r--.  1 root root  193 Oct 31  2018 .bash_profile
-rw-r--r--.  1 root root  231 Oct 31  2018 .bashrc

3.1 文件详解

.bash_logout    -- 当用户退出登录状态会执行的命令
.bash_profile   -- 别名和环境变量(只针对某个用户)
.bashrc         -- 别名和环境变量(只针对某个用户)

3.2 创建用户测试

[root@sec ~]# cd /etc/skel/
[root@sec skel]# touch yunxuan.txt
[root@sec skel]# ll -a
total 24
drwxr-xr-x.  2 root root   81 Oct 11 17:53 .
drwxr-xr-x. 77 root root 8192 Oct 11 17:47 ..
-rw-r--r--.  1 root root   18 Oct 31  2018 .bash_logout
-rw-r--r--.  1 root root  193 Oct 31  2018 .bash_profile
-rw-r--r--.  1 root root  231 Oct 31  2018 .bashrc
-rw-r--r--.  1 root root    0 Oct 11 17:53 yunxuan.txt
[root@sec skel]# useradd test
[root@sec skel]# cd /home/test/
[root@sec test]# ll -a
total 12
drwx------. 2 test test  81 Oct 11 17:54 .
drwxr-xr-x. 5 root root  46 Oct 11 17:54 ..
-rw-r--r--. 1 test test  18 Oct 31  2018 .bash_logout
-rw-r--r--. 1 test test 193 Oct 31  2018 .bash_profile
-rw-r--r--. 1 test test 231 Oct 31  2018 .bashrc
-rw-r--r--. 1 test test   0 Oct 11 17:53 yunxuan.txt

useradd test --> /home/test/ --> 目录中的数据内容会参考/etc/skel目录中的信息

3.3 /etc/skel 目录作用

  1. 目录中可以存储运维操作规范说明文件
  2. 调整命令提示符信息
# 问题
[root@sec yunxuan]# rm -fr ./.b*
[root@sec yunxuan]# ll -a
total 0
drwx------. 2 yunxuan yunxuan  6 Oct 11 18:02 .
drwxr-xr-x. 4 root    root    34 Oct 11 17:55 ..
[root@sec yunxuan]# su - yunxuan
Last login: Mon Oct 11 14:17:06 CST 2021 on pts/4
-bash-4.2$ 
# 恢复
-bash-4.2$ cp /etc/skel/.b* /home/yunxuan/
-bash-4.2$ ll -a
total 12
drwx------. 2 yunxuan yunxuan  62 Oct 11 18:06 .
drwxr-xr-x. 4 root    root     34 Oct 11 17:55 ..
-rw-r--r--. 1 yunxuan yunxuan  18 Oct 11 18:06 .bash_logout
-rw-r--r--. 1 yunxuan yunxuan 193 Oct 11 18:06 .bash_profile
-rw-r--r--. 1 yunxuan yunxuan 231 Oct 11 18:06 .bashrc
-bash-4.2$ logout
[root@sec yunxuan]# su - yunxuan
Last login: Mon Oct 11 18:03:08 CST 2021 on pts/0
[yunxuan@sec ~]$ ll -a
total 16
drwx------. 2 yunxuan yunxuan  83 Oct 11 18:06 .
drwxr-xr-x. 4 root    root     34 Oct 11 17:55 ..
-rw-------. 1 yunxuan yunxuan  38 Oct 11 18:06 .bash_history
-rw-r--r--. 1 yunxuan yunxuan  18 Oct 11 18:06 .bash_logout
-rw-r--r--. 1 yunxuan yunxuan 193 Oct 11 18:06 .bash_profile
-rw-r--r--. 1 yunxuan yunxuan 231 Oct 11 18:06 .bashrc

3.4 扩展 - 用户家目录中的其他文件

3.4.1 .bash_history

.bash_history   -- 历史命令记录文件

曾经输入的历史命令保存位置

  1. 保存在内存中(如果重启可能会丢失)
history     -- 可查看内存中的历史命令
history -c  -- 清空内存中的历史命令
  1. 保存在磁盘文件中(.bash_history)

3.4.2 .viminfo

.viminfo        -- vim 样式设置

自动加载 vim 样式信息

#!/bin/bash
# 编写人:
# 编写时间:
# 脚本作用:

相关文章

  • 文件和目录权限说明

    1. 文件信息 1.1 实验环境 1.1.1 无任何权限 yunxuan_root.txt(无任何权限)yunxu...

  • Linux 文件普通权限

    一、文件权限10个字符对应类型和权限 二、Linux普通文件和Linux目录读、写、执行权限说明 标注:Linux...

  • Linux常见命令

    chmod功能说明: 1.变更文件或目录的权限补充说明: 在UNIX系统家族里,文件或目录权限的控制分别以读取,写...

  • Linux~权限管理命令

    一、文件和目录权限 权限分为3个字符为一组,分别对应用户、用户组,其他 1、文件类型说明 -:普通文件 d:目录文...

  • linux--chmod

    chmod 用来变更文件或目录的权限 补充说明 chmod命令 用来变更文件或目录的权限。在UNIX系统家族里,文...

  • Android 危险权限目录

    危险权限 说明 查看权限目录 危险权限目录

  • 第十六天课堂笔记 3月21号

    学习内容【文件】权限 【目录】权限***、 【文件】权限 【目录】权限*** 字符和数字(8进制)权限知识****...

  • rwx读写执行对文件和目录的意义

    权限文件目录r查看列出目录内容w修改在目录内新建删除文件x执行可以进入目录 对目录-wx的权限,有写和执行权限,既...

  • 文件和目录权限

    1、Linux权限介绍2、Linux文件属性3、如何改变Linux文件属性权限4、新建文件默认权限 1、Linux...

  • 【Linux】文件的权限管理

    Linux下文件的权限管理 文章主要从以下几个方面展开介绍: 文件的属性和权限 文件的权限和属性的更改 文件和目录...

网友评论

      本文标题:文件和目录权限说明

      本文链接:https://www.haomeiwen.com/subject/jeqroltx.html