2019-04-11

用户

添加用户

[root@oldboyedu59 ~]# useradd oldboy 
[root@oldboyedu59 ~]# id oldboy 
uid=1000(oldboy) gid=1000(oldboy) groups=1000(oldboy)

设置密码

[root@oldboyedu59 ~]# passwd  oldboy
Changing password for user oldboy.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

切换用户


[root@oldboyedu59 ~]# su  -  oldboy 
[oldboy@oldboyedu59 ~]$ whoami 
oldboy
[oldboy@oldboyedu59 ~]$ id
uid=1000(oldboy) gid=1000(oldboy) groups=1000(oldboy)

rw-r--r--的含义

rw-所有者 --r所属用户组 r--其他人(陌生人)
user group other
u g o

rwx-的代表数字和意思

r 4 read 是否可读
w 2 write 是否可写
x 1 executable 是否可以运行 (执行)

  • 0
[root@oldboyedu59 oldboy]# ls -l /etc/hosts  /bin/ls 
-rwxr-xr-x. 1 root root 117680 Oct 31 03:16 /bin/ls
-rw-r--r--  1 root root    188 Apr  1 17:13 /etc/hosts

-rwxr-xr-x
421401401
7 5 5
-rw-r--r--
420400400
6 4 4

权限与用户的对应关系图:

TIM图片20190411152549.png

例题

755

-rwxr-xr-x. 1 root root 117680 Oct 31 03:16 /bin/ls

750 -rwxr-x---
640 -rw-r-----
604 -rw----r--
644 -rw-r--r--
400 -r--------

修改权限 chmod

[root@oldboyedu59 oldboy]# ls -l oldboy.txt
-rw-r--r-- 2 root root 7 Apr 10 11:57 oldboy.txt
[root@oldboyedu59 oldboy]# chmod 755 oldboy.txt
[root@oldboyedu59 oldboy]# ls -l oldboy.txt
-rwxr-xr-x 2 root root 7 Apr 10 11:57 oldboy.txt

根据字符形式修改权限


[root@oldboyedu59 oldboy]# chmod u-w oldboy.txt
[root@oldboyedu59 oldboy]# ll  oldboy.txt
-r--r--r-- 2 root root 7 Apr 10 11:57 oldboy.txt
[root@oldboyedu59 oldboy]# chmod u+w oldboy.txt
[root@oldboyedu59 oldboy]# ll oldboy.txt
-rw-r--r-- 2 root root 7 Apr 10 11:57 oldboy.txt
[root@oldboyedu59 oldboy]# chmod u=w oldboy.txt
[root@oldboyedu59 oldboy]# ll oldboy.txt
--w-r--r-- 2 root root 7 Apr 10 11:57 oldboy.txt

给每个位置都加上执行权限 ugo

[root@oldboyedu59 oldboy]# chmod ugo+x oldboy.txt
[root@oldboyedu59 oldboy]# chmod a-x oldboy.txt
[root@oldboyedu59 oldboy]# 
[root@oldboyedu59 oldboy]# ll oldboy.txt
-rw-r--r-- 2 root root 7 Apr 10 11:57 oldboy.txt
[root@oldboyedu59 oldboy]# chmod a+x oldboy.txt
[root@oldboyedu59 oldboy]# ll oldboy.txt
-rwxr-xr-x 2 root root 7 Apr 10 11:57 oldboy.txt
[root@oldboyedu59 oldboy]# chmod  a-x oldboy.txt
[root@oldboyedu59 oldboy]# ll oldboy.txt
-rw-r--r-- 2 root root 7 Apr 10 11:57 oldboy.txt
[root@oldboyedu59 oldboy]# chmod +x oldboy.txt
[root@oldboyedu59 oldboy]# ll oldboy.txt
-rwxr-xr-x 2 root root 7 Apr 10 11:57 oldboy.txt

chmod ugo+x oldboy.txt=chmod a+x oldboy.txt

你可能感兴趣的:(2019-04-11)