linux 权限管理命令chown、chgrp、umask、linux新建文件或目录的默认权限755

chown /bin/chown
chown [用户] [文件或目录] 改变文件或目录的所有者
只有root可以改变文件或目录的所有者

root用户:
mkdir /tmp
touch /tmp/test.file
useradd meinv
passwd meinv
chown meinv /tmp/test.file

meinv用户:
touch /tmp/test.file1
chown root /tmp/test.file1 失败


chgrp /bin/chgrp

chgrp [用户组] [文件或目录] 改变文件或目录的所属组

groupadd student
chgrp student /tmp/test.file


umask

语法:umask [-S] -S以rwx形式显示新建文件或目录的缺省权限
shell内置命令 执行权限:所有用户
显示、设置文件的缺省权限

umask -S
u=rwx,g=rx,o=rx
表示现在新建一个文件或目录,这个新建文件或目录的缺省权限是u=rwx,g=rx,o=rx
umask
0022
777-022=755

mkdir testdir
touch testfile
ls -dl testdir testfile
drwxr-xr-x. 2 root root 4096 8月 18 22:13 testdir
-rw-r--r--. 1 root root 0 8月 18 22:13 testfile
文件比目录少了x权限,在linux里所有的新建文件默认都没有执行权限

设置umask
rwxr-xr-- 754 777-754=023
umask 023
mkdir test2
ls -ld test2
drwxr-xr--. 2 root root 4096 8月 18 22:24 test2

在linux里,新建一个文件或目录的默认权限是755,文件少了可执行权限,可以通过umask查看

猜你喜欢

转载自www.cnblogs.com/BaiLaowu/p/9499011.html