Linux账户组管理及权限练习

1.使用id命令查看root账户信息

[root@server ~]# id root

用户id=0(root) 组id=0(root) 组=0(root)

2.使用id命令查看自己的普通账户信息

[root@server ~]# id kxy

用户id=1000(kxy) 组id=1000(kxy) 组=1000(kxy),10(wheel)

3.新建账户test1,并查看账户信息:

[root@server ~]# useradd test1

[root@server ~]# id test1

用户id=1001(test1) 组id=1001(test1) 组=1001(test1)

4.新建账户test2并制定UID为2021

[root@server ~]# useradd -u 2021 test2

[root@server ~]# id test2

用户id=2021(test2) 组id=2021(test2) 组=2021(test2)

5.删除上述新建账户test1及test2

[root@server ~]# userdel test1

[root@server ~]# userdel test2

6.完成下列设置

(1)新建账户test3

[root@server ~]# useradd test3

(2)并设置密码:

[root@server ~]# echo "123456" | passwd --stdin test3 >> /dev/null

(3)修改test3账户的id为5000:

[root@server ~]# usermod -u 5000 test3

[root@server ~]# id test3

用户id=5000(test3) 组id=1001(test3) 组=1001(test3)

(4)修改test3账户的工作组为之前的test1工作组:

[root@server ~]# groupadd test1

[root@server ~]# gpasswd -a test3 test1

正在将用户“test3”加入到“test1”组中

(5)查看test3的信息:cat  /etc/passwd

[root@server ~]# cat /etc/passwd | tail -1

test3:x:5000:1001::/home/test3:/bin/bash

(6)使用test3账户登录

[root@server ~]# su - test3

[test3@server ~]$

7.新建账户test4,并设置密码,且为不可登录,尝试登录

[root@server ~]# useradd -s /sbin/nologin test4

[root@server ~]# echo "123456" | passwd --stdin test4 >> /dev/null

[root@server ~]# su - test4

This account is currently not available.

8.进入/etc  目录查看详细信息,注意权限项:

[root@server ~]# sudo ls -l /etc/

9.进入 ~目录新建t1目录在其中新建文件temp1.txt完成如下操作

(1)查看temp.txt的权限:ls  -l  temp1.txt

[root@server ~]# mkdir t1

[root@server ~]# cd t1

[root@server t1]# touch temp1.txt

[root@server t1]# ll temp1.txt

-rw-r--r--. 1 root root 0  9月 29 14:48 temp1.txt

Linux账户组管理及权限练习_第1张图片

(2)修改权限为完整权限并查看:

[root@server t1]# chmod 777 temp1.txt

[root@server t1]# ll temp1.txt

-rwxrwxrwx. 1 root root 0  9月 29 14:48 temp1.txt

(3)新建temp2.txt,并使用数字法设置权限为rw-rw-r--

[root@server t1]# touch temp2.txt

[root@server t1]# chmod 664 temp2.txt

[root@server t1]# ll temp2.txt

-rw-rw-r--. 1 root root 0  9月 29 14:55 temp2.txt

Linux账户组管理及权限练习_第2张图片

10.新建账户test5 并设置密码为123456后按如下操作:

(1)查看test5的账户信息:cat  /etc/passwd

[root@server ~]# useradd -p "123456" test5

[root@server ~]# cat /etc/passwd | tail -1

test5:x:1001:1001::/home/tets5:/bin/bash

​​​​​​​(2)新建文件temp3.txt

[root@server ~]# touch temp3.txt

​​​​​​​​​​​​​​Linux账户组管理及权限练习_第3张图片

​​​​​​​(3)将temp3.txt 文件加入test5账户及工作组中:

[root@​​​​​​​server ~]# chown test5:test5 temp3.txt

[root@server ~]# ll temp3.txt

-rw-r--r--. 1 test5 test5 0  9月 29 15:01 temp3.txt

11.按如下操

(1)作​​​​​​​新建目录k1

[root@server ~]# mkdir k1

​​​​​​​(2)进入目录新建文件temp4.txt

[root@server ~]# cd k1

[root@server k1]# touch temp4.txt

​​​​​​​(3)查看temp4隐藏权限: lsattr  temp4.txt

[root@server k1]# lsattr temp4.txt

---------------------- temp4.txt

​​​​​​​(4)将“hello” 字符串写入到temp4.txt文件中

[root@server k1]# echo "hello" >> temp4.txt

[root@server k1]# cat temp4.txt

hello

​​​​​​​(5)设置temp4.txt不可删除隐藏权限属性,检查是否可删除:

[root@server k1]# chattr +a temp4.txt

[root@server k1]# lsattr temp4.txt

-----a---------------- temp4.txt

[root@server k1]# rm -f temp4.txt

rm: 无法删除 'temp4.txt': 不允许的操作

​​​​​​​(6)删除temp4.txt隐藏权限:

[root@server k1]# chattr -a temp4.txt

[root@server k1]# lsattr temp4.txt

---------------------- temp4.txt

​​​​​​​(7)尝试删除temp4.txt

[root@server k1]# rm -f temp4.txt

你可能感兴趣的:(linux,运维,服务器,用户组,权限)