一、命令
1、增删用户
useradd a1 新建用户a1 cat /etc/passwd 系统保留uid为0-99,0为root,新建用户从500开始
userdel -r 删除用户
usermod -L 锁定用户
usermod -U 解锁
注意:当我们正常通过useradd a1建立用户时(此时没有设置密码,用户a1不能登录系统),我们查看cat /etc/shadow可以看出密码为为 !,*,x时表示此用户无法登录
[[email protected] tmp]# useradd a1
[[email protected] tmp]# cat /etc/shadow
root:$6$XonOi4Go0YWZh2DD$MhMEqM/mpc7XNcyiYMRdgrP3xOhVanG74LYCAVj1lrCWN9YzQtDvCw3xzdVql..4c10V6YVkjgTr0jlibBQbO1:17122:0:99999:7:::
bin:*:15980:0:99999:7:::
daemon:*:15980:0:99999:7:::
adm:*:15980:0:99999:7:::
lp:*:15980:0:99999:7:::
sync:*:15980:0:99999:7:::
shutdown:*:15980:0:99999:7:::
halt:*:15980:0:99999:7:::
mail:*:15980:0:99999:7:::
uucp:*:15980:0:99999:7:::
operator:*:15980:0:99999:7:::
games:*:15980:0:99999:7:::
gopher:*:15980:0:99999:7:::
ftp:*:15980:0:99999:7:::
nobody:*:15980:0:99999:7:::
dbus:!!:17122::::::
rpc:!!:17122:0:99999:7:::
vcsa:!!:17122::::::
abrt:!!:17122::::::
saslauth:!!:17122::::::
postfix:!!:17122::::::
haldaemon:!!:17122::::::
ntp:!!:17122::::::
apache:!!:17122::::::
rpcuser:!!:17122::::::
nfsnobody:!!:17122::::::
sshd:!!:17122::::::
tcpdump:!!:17122::::::
c2:$6$u0L.la3U$iclu6Lk0YDg93c.g7UdffR88AhoUTq5K/bkjT90MWynj4TsyYh8TdnSKhmyIGQjSRIfY6MwDW6H/azcAyEu3R0:17135:0:99999:7:::
c3:$6$vH1Ki1Gi$Tpmm0RLfYeA/SS3JLg408PWswnQn4vED0Vuz4xVkJ5I6qWg50RrqHk8ixRtSyNJM8bsUtRRL9Bgdof/qmnwBI.:17135:0:99999:7:::
a1:!!:17135:0:99999:7:::
2、组的管理
groupadd -g 1000 market 建立组market,并手动设定GID为1000
groupdel market 删除组market
gpasswd -a a1 market 将用户a1加入组market中
gpasswd -d a1 market 将用户a1从组market中移除
gpasswd -A a1 market 将用户设置为组market的管理员
3、更改文件权限chmod
[[email protected] tmp]# touch test.txt
[[email protected] tmp]# ls -laihs
total 24K
261633 4.0K drwxrwxrwt. 5 root root 4.0K Nov 30 18:35 .
2 4.0K dr-xr-xr-x. 23 root root 4.0K Nov 17 16:06 ..
266164 4.0K drwxr-xr-x. 2 root root 4.0K Nov 30 15:27 aaa
262057 4.0K -rwxrwx---. 1 root c1group 58 Nov 30 18:18 gongxiang.txt
261872 4.0K drwxrwxrwt. 2 root root 4.0K Nov 17 16:06 .ICE-unix
262063 0 -rw-r--r--. 1 root root 0 Nov 30 18:35 test.txt
261873 4.0K drwxr-xr-x. 5 root root 4.0K Aug 26 05:34 vmware-tools-distrib
[[email protected] tmp]# chmod 775 test.txt
[[email protected] tmp]# ls -laihs
total 24K
261633 4.0K drwxrwxrwt. 5 root root 4.0K Nov 30 18:35 .
2 4.0K dr-xr-xr-x. 23 root root 4.0K Nov 17 16:06 ..
266164 4.0K drwxr-xr-x. 2 root root 4.0K Nov 30 15:27 aaa
262057 4.0K -rwxrwx---. 1 root c1group 58 Nov 30 18:18 gongxiang.txt
261872 4.0K drwxrwxrwt. 2 root root 4.0K Nov 17 16:06 .ICE-unix
262063 0 -rwxrwxr-x. 1 root root 0 Nov 30 18:35 test.txt
261873 4.0K drwxr-xr-x. 5 root root 4.0K Aug 26 05:34 vmware-tools-distrib
4、更改文件或目录的属主或属组
chown :c1group share.txt 将share.txt文件属组改为c1group
chown c2:c1group 111.txt 将111.txt 文件属主改为c2,属组为c1group
5、setfacl 也可使用acl规则定义
setfacl -m stu:rwx hello_world 让用户stu拥有rwx权限
setfacl -m g:student:rx hello_world 让组student拥有rwx权限
setfacl -x g:student hello_world 解除student组对文件的权限