Linux练习1

1、创建group2组
2、创建xiaoxiao用户并指定group2作为它的基本组
3、给xiaoxiao用户设置密码为123
4、删除xiaoxiao用户的同时删除与之相关的文件和目录

[root@xiaokeai ~]# groupadd group2
[root@xiaokeai ~]# grep group2 /etc/group
group2:x:1004:

[root@xiaokeai ~]# useradd xiaoxiao -g group2
[root@xiaokeai ~]# id xiaoxiao
uid=1002(xiaoxiao) gid=1002(group2) groups=1002(group2)


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

[root@xiaokeai ~]# userdel -r xiaoxiao
[root@xiaokeai ~]# grep group2 /etc/group
group2:x:1002:

[root@xiaokeai ~]# groupdel group2
[root@xiaokeai ~]# grep group2 /etc/group
 


1、root用户在/tmp下创建一个1.txt的文件,写入123的内容并查看,修改1.txt文件的其他人的权限为读写。

[root@xiaokeai ~]# touch /tmp/1.txt
[root@xiaokeai ~]# echo 123 >/tmp/1.txt
[root@xiaokeai ~]# cat /tmp/1.txt
123

[redhat@xiaokeai tmp]$ ls -l
total 4
-rw-r--r--. 1 root root  0 Jul 19 10:57 111
-rw-r--r--. 1 root root  0 Jul 19 15:54 1.txt


[root@xiaokeai ~]# cd /tmp
[root@xiaokeai tmp]# chmod o=rw 1.txt


[redhat@xiaokeai tmp]$ ls -l
total 4
-rw-r--r--. 1 root root  0 Jul 19 10:57 111
-rw-r--rw-. 1 root root  4 Jul 19 15:58 1.txt

 


2、root用户在/tmp下创建root.txt文件,写入“这是root”内容。修改其他人的权限为·。创建一个xiaohong和xiaoming两个用户,并设置密码xh和xm,让xiaohong可以对root.txt有读写的权限,让xiaoming可以对root.txt有读的权限。

[root@xiaokeai ~]# touch /tmp/root.txt
[root@xiaokeai ~]# echo this is root >/tmp/root.txt
[root@xiaokeai ~]# cat /tmp/root.txt
this is root

[root@xiaokeai ~]# cd /tmp
[root@xiaokeai tmp]# chmod o=- root.txt
[root@xiaokeai tmp]# cd ~
 

[root@xiaokeai ~]# useradd -g xiaohong xiaohong
useradd: warning: the home directory /home/xiaohong already exists.
useradd: Not copying any file from skel directory into it.
[root@xiaokeai ~]# id xiaohong
uid=1002(xiaohong) gid=1001(xiaohong) groups=1001(xiaohong)
[root@xiaokeai ~]# groupadd xiaoming
[root@xiaokeai ~]# useradd -g xiaoming xiaoming
[root@xiaokeai ~]# id xiaoming
uid=1003(xiaoming) gid=1004(xiaoming) groups=1004(xiaoming)
[root@xiaokeai ~]# passwd xiaohong
Changing password for user xiaohong.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

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

[root@xiaokeai ~]# setfacl -m u:xiaohong:rw /tmp/root.txt
[root@xiaokeai ~]# setfacl -m u:xiaoming:r /tmp/root.txt
[root@xiaokeai ~]# getfacl /tmp/root.txt
getfacl: Removing leading '/' from absolute path names
# file: tmp/root.txt
# owner: root
# group: root
user::rw-
user:xiaohong:rw-
user:xiaoming:r--
group::r--
mask::rw-
other::---


3、xiaoming用户在/tmp下创建一个xiaoming.txt的文件,修改xiaoming.txt的属者和属组为xiaohong。

[xiaoming@xiaokeai ~]$ touch /tmp/xiaoming.txt
[xiaoming@xiaokeai ~]$ ls -l /tmp/xiaoming.txt
-rw-r--r--. 1 xiaoming xiaoming 0 Jul 19 18:08 /tmp/xiaoming.txt
[root@xiaokeai ~]# chown xiaohong:xiaohong /tmp/xiaoming.txt
[xiaoming@xiaokeai ~]$ ls -l /tmp/xiaoming.txt
-rw-r--r--. 1 xiaohong xiaohong 0 Jul 19 18:08 /tmp/xiaoming.txt
 

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值