shallow丿ovelinux
r=4,w=2,x=1 selinux开启则权限后面会有个. 更改SElinux配置文件,将永久关闭SElinux [root@localhost ~]# vi /etc/selinux/config #将默认的enforcing改成disabled,permissive警告
chmod 700 /root/.ssh chmod u=rwx,g=rx,o=r /home/1 chmod a+x /home/1 #全部者权限均可执行x chmod a-x /home/1 #全部者权限都不可执行x chmod g-x /home/1 #全部组不可执行x
chmod -R #递归更改
[root@localhost ~]# adduser user1 #建立普通用户或useradd [root@localhost ~]# touch /home/1.txt [root@localhost ~]# chown hello /home/1.txt #更改全部者 [root@localhost ~]# ls -l /home/ [root@localhost ~]# userdel user1 #删除用户 [root@localhost ~]# userdel -r user1 #删除用户及用户主目录
[root@localhost ~]# groupadd userall [root@localhost ~]# useradd -g userall user1 #新建用户添加到用户组中。-g 所属组,-d家目录,-s所用的shell [root@localhost ~]# usermod -g 组名 用户名 #添加用户所在组 [root@localhost ~]# usermod -d 目录名 用户名 #改变该用户登录的初始目录
[root@localhost ~]# cat /etc/passwd 用户:已加密密码:用户id:用户所在组id:注释:用户主目录:该用户所使用的shell(解析器)
[root@localhost ~]# touch /home/2.txt [root@localhost ~]# chgrp userall /home/2.txt #更改全部组 [root@localhost ~]# ls -l /home/
[root@localhost ~]# chown hello:userall /home/3.txt #更改全部者和全部组 [root@localhost ~]# chown :userall /home/4.txt #只更改全部组 [root@localhost ~]# chmod -R #递归更改
[root@localhost ~]# usermod -G groupname username(把该用户从其余用户组移除,并添加到指定的用户组内) [root@localhost ~]# usermod -a goupname username
[root@localhost ~]# touch /home/1.txt # 文件默认权限为644 [root@localhost ~]# mkdir /home/1/ #目录权限默认为755 [root@localhost ~]# umask #0022
umask 002 touch /home/1.txt #664 mkdir /home/1/ #775
umask算法 666=(rw-rw-rw)-003(-------wx)=664(rw-rw-r--) 777=(rwxrwxrwx)-003(-------wx)=774(rwxrwxr--)
查看文件权限 [root@localhost ~]# touch /home/1.txt [root@localhost ~]# chattr +i /home/1.txt [root@localhost ~]# vi 1.txt [root@localhost ~]# head -n2 /etc/passwd >> /home/1.txt #提示权限不够 [root@localhost ~]# ls -l 1.txt #rw-rw-r-- [root@localhost ~]# lsattr /home/1.txt #----i------------ 而 [root@localhost ~]# touch 2.txt [root@localhost ~]# lsattr 2.txt #-----------------
[root@localhost ~]# chattr +i /home/1.txt #加i权限 [root@localhost ~]# chattr -i /home/1.txt #减i权限 [root@localhost ~]# chattr +a /home/2.txt #只能追加,不能删除,不能更改 [root@localhost ~]# lsattr /home/2.txt #-----a-----------
查看目录权限 [root@localhost ~]# lsattr -d /home/111
文件追加: [root@localhost ~]# mkdir /home/222 [root@localhost ~]# chattr +i /home/222 #能够写已经存在的文件 [root@localhost ~]# touch /home/222/2.txt [root@localhost ~]# chattr -i /home/222 [root@localhost ~]# chattr +a /home/222 [root@localhost ~]# touch /home/222/2.txt #文件追加
当ls发现有一个文件结尾后面加~,则这是个缓存,当保存后则自动覆盖到原来的文件里算法