Linux-Practice-4-2

  1. 将 student用户的家目录复制到/tmp目录中,并保持源文件的属性不变。
  • cp -a = -dR --preserve=all,可以保持属性 ✅
  • 但路径有问题:student 用户的家目录通常是 /home/student,不是 /opt/student
1
2
3
4
5
6
7
8
[root@localhost ~]# grep student /etc/passwd
student:x:1004:1005::/home/student:/bin/bash
[root@localhost ~]#
[root@localhost ~]# cp -a /home/student/ /tmp/student
[root@localhost ~]#
[root@localhost ~]# ll -ld /tmp/student/
drwx------. 3 student student 78 5月 23 17:59 /tmp/student/
[root@localhost ~]#
  1. 创建一个名为 financial 的组。
1
2
3
4
5
6
[root@localhost ~]# groupadd financial
[root@localhost ~]#
[root@localhost ~]# tail -3 /etc/group
user3:x:1004:
student:x:1005:
financial:x:1006:
  1. 创建一个名为test1的用户,指定其UID为1600,将fnancial 组设置为 testl用户的基本组。
1
2
3
4
5
[root@localhost ~]# useradd -u 1600 -g financial test1
[root@localhost ~]# id test1
uid=1600(test1) gid=1006(financial) 组=1006(financial)
[root@localhost ~]#
[root@localhost ~]#
  1. 通过非交互方式为用户test1设置密码 123.
1
2
3
4
[root@localhost ~]# echo '123' | passwd --stdin test1
更改用户 test1 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]#
  1. 另外打开一个终端,以test1用户的身份登录系统。在test1的家目录中创建一个名为 test1.txt 的文件,并査看 test1.txt 文件的权限设置。
1
2
3
4
5
6
7
8
9
Last login: Sat May 23 17:47:12 2026 from 192.168.10.2
[root@localhost ~]# su - test1
[test1@localhost ~]$
[test1@localhost ~]$
[test1@localhost ~]$ touch /home/test1/test1.txt
[test1@localhost ~]$
[test1@localhost ~]$ ll test1.txt
-rw-r--r--. 1 test1 financial 0 5月 23 20:48 test1.txt
[test1@localhost ~]$
  1. 首先对文件 test1.txt进行权限设置,要求文件所有者具有读写权限,所属组和其他用户具有只读权限。然后,使test1用户退出登录。
1
2
3
4
5
6
7
[test1@localhost ~]$ chmod 644 /home/test1/test1.txt 
[test1@localhost ~]$
[test1@localhost ~]$ ll /home/test1/test1.txt
[test1@localhost ~]$
[test1@localhost ~]$ exit
登出
[root@localhost ~]#
  1. 将test1 用户锁定,禁止其登录。再次打开一个终端,尝试能否以 test1 用户的身份登录。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@localhost ~]# passwd -l test1
锁定用户 test1 的密码 。
passwd: 操作成功
[root@localhost ~]# ssh test1@192.168.10.3
The authenticity of host '192.168.10.3 (192.168.10.3)' can't be established.
ECDSA key fingerprint is SHA256:GHFP5IRyvqkvsd/amMCQc+4AYvp9S7gRMPrusqfgW8c.
ECDSA key fingerprint is MD5:8b:ca:1a:0d:0f:81:13:50:f9:13:10:aa:83:ad:c8:5e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.3' (ECDSA) to the list of known hosts.
test1@192.168.10.3's password:
Permission denied, please try again.
test1@192.168.10.3's password:
Permission denied, please try again.
test1@192.168.10.3's password:
  1. 将test1用户解锁,在终端中尝试能否以 test1 用户的身份登录。
1
2
3
4
5
6
7
8
9
10
[root@localhost ~]# passwd -u test1
解锁用户 test1 的密码。
passwd: 操作成功
[root@localhost ~]#
[root@localhost ~]# ssh test1@192.168.10.3
test1@192.168.10.3's password:
Last failed login: Sat May 23 21:28:11 CST 2026 from 192.168.10.3 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Sat May 23 21:25:29 2026
[test1@localhost ~]$
  1. 将用户testl家目录中的test1.txt文件的所有者改为root,所属组改为users
1
2
3
4
5
6
7
8
9
10
11
12
[test1@localhost ~]$ chown root:users /home/test1/test1.txt
chown: 正在更改"/home/test1/test1.txt" 的所有者: 不允许的操作
[test1@localhost ~]$
[test1@localhost ~]$ exit
登出
Connection to 192.168.10.3 closed.
[root@localhost ~]#
[root@localhost ~]# chown root:users /home/test1/test1.txt
[root@localhost ~]#
[root@localhost ~]# ll /home/test1/test1.txt
-rw-r--r--. 1 root users 0 5月 23 20:48 /home/test1/test1.txt
[root@localhost ~]#

Linux-Practice-4-2
https://hexo-blog.zixuan.ah.cn/20260523/Linux-Practice-4-2/
作者
ZhienXuan
发布于
2026年5月23日
许可协议