文件或目錄權限chmod,更改所有者和所屬組chown ,umask的使用 ,隱藏權限的使用 lsattr,chattr
r = 可讀w =可寫 x=可執行
[root@alex ~]# ls -l
total 20
drwxr-xr-x. 2 root root 4096 Oct 25 08:49 1.txt
drwxr-xr-x. 2 root root 4096 Oct 16 14:01 c
drwx所有者的權限 r-x 所屬組的權限 r-x除去所有者所屬組的權限
r=4 w=2 x=1 rwx=7 r-x=5 r-x=5 文件755
[root@alex ~]# chmod 700 1.txt chmod的使用方法
total 20
drwx------. 2 root root 4096 Oct 25 08:49 1.txt
chmod -R 777 dataitu chomd只對文件或者目錄本身生效,加上選項-R 就會在目錄的本身或者子目錄子文件一起生效
文件當中的.文件 是沒有關閉selinux
getenforce
setenforce 0 關閉
[root@alex ~]# getenforce
Permissive
[root@alex ~]# vi /etc/selinux/config 更改配置權限 的命令
chmod 其他寫法 u=用戶 g=組 o=其他用戶
[root@alex ~]# chmod u=rwx,g=r--,o=r-- 1.txt 寫法
[root@alex ~]# ls -l
total 20
drwxr--r--. 2 root root 4096 Oct 25 08:49 1.txt
[root@alex ~]# chmod u-x 1.txt 也可以這麼寫 u-x g-x a-x
[root@alex ~]# ls -l
total 20
drw-r--r--. 2 root root 4096 Oct 25 08:49 1.txt
chown 可以更改所有者 和所屬組
[root@alex ~]# chown dabaitu /tmp/alex 更改權限的寫法
[root@alex ~]# chown root:dabaitu /tmp/alex 同時更改的寫法
[root@alex ~]# ls -l /tmp/
total 16
drwxr-xr-x. 2 root root 4096 Oct 25 08:54 2.txt
srwxr-xr-x. 1 root root 0 Oct 21 10:47 Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
drwxr-xr-x. 3 root dabaitu 4096 Oct 24 09:25 alex
[root@alex ~]# chown :user /tmp/alex 只更改組 的寫法
[root@alex ~]# ls -l /tmp
total 16
drwxr-xr-x. 2 root root 4096 Oct 25 08:54 2.txt
srwxr-xr-x. 1 root root 0 Oct 21 10:47 Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
drwxr-xr-x. 3 root user 4096 Oct 24 09:25 alex
[root@alex ~]# chown -R root:user /tmp/alex 也可以這樣加上R選項 同時更改文件的子文件子目錄
[root@alex ~]# ls -l /tmp/alex
total 4
drwxr-xr-x. 2 root user 4096 Oct 24 09:42 1
umask
目錄必須要有x權限 ,沒有x權限我們都不能瀏覽目錄 ,更何況操作呢
umask 是決定默認和目錄文件的權限
[root@alex ~]# umask
0022
必須用rwxrwxrwx 去減 才能得出權限
[root@alex ~]# umask 003 修改umak
[root@alex ~]# umask
0003
[root@alex ~]# umask 022
[root@alex ~]# umask
0022
chattr lsattr 隱藏權限
[root@alex ~]# chattr +i 1.txt
加上i權限不可以寫,不可以更改名字 不可以刪除 也無法創建
[root@alex ~]# chattr -i 1.txt 接觸的用法
查看是
lsattr 1.txt
[root@alex ~]# chattr +a 2.txt 只能追加 不能刪除 ,不能更改 ,不能重命名
[root@alex ~]# lsattr 2.txt 查看a權限
-----a-------e-- 2.txt
[root@alex ~]# chattr -a 2.txt -a可以把權限去掉
[root@alex ~]# lsattr 2.txt
-------------e-- 2.txt
[root@alex ~]# lsattr -d m 減d查看目錄本身 給目錄添加的時候 只可以追加重定向
-------------e-- m
[root@alex ~]# chattr +i m 用法
[root@alex ~]# lsattr -d m
----i--------e-- m
lsattr -R 可以查看文件的下面的子文件子目錄 全部列出來
lsattr -a 全部包括影藏的
[root@alex ~]# lsattr -a /root/
-------------e-- /root/.cache
-------------e-- /root/.pydistutils.cfg
-------------e-- /root/.tcshrc
-------------e-- /root/zx
-------------e-- /root/2.txt
-------------e-- /root/.bash_logout
-------------e-- /root/.cshrc
-------------e-- /root/m
-------------e-- /root/.bash_history
-------------e-- /root/p
-------------e-- /root/.ssh
-------------e-- /root/.
-------------e-- /root/c
-------------e-- /root/.pip
-------------e-- /root/.bashrc
-------------e-- /root/..
-------------e-- /root/3.txt
-------------e-- /root/.bash_profile