Kevin_306

02Linux入门-命令练习 更改文件的所有人和属组 20210116

02Linux入门-命令练习 20210116

将SELNUX=enforcing改为SELNUX=disabled

root@centos7 ~]# nano /etc/selinux/config 配置文件,将SELNUX=enforcing改为SELNUX=disabled 

[root@centos7 ~]# getenforce (#Enforcing:强制模式。代表SELinux在运行中,且已经开始限制domain/type之间的验证关系)
Enforcing
[root@centos7 ~]# cat /etc/selinux/config (#查看配置文件)

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 


[root@centos7 ~]# nano /etc/selinux/config(#nano编辑配置文件)
-bash: nano: command not found
[root@centos7 ~]# yum -y install nano(#安装nano)
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.sjtu.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: ftp.sjtu.edu.cn
base                                                                                                   | 3.6 kB  00:00:00     
extras                                                                                                 | 2.9 kB  00:00:00     
updates                                                                                                | 2.9 kB  00:00:00     
updates/7/x86_64/primary_db                                                                            | 4.7 MB  00:00:01     
Resolving Dependencies
--> Running transaction check
---> Package nano.x86_64 0:2.3.1-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================
 Package                    Arch                         Version                             Repository                  Size
==============================================================================================================================
Installing:
 nano                       x86_64                       2.3.1-10.el7                        base                       440 k

Transaction Summary
==============================================================================================================================
Install  1 Package

Total download size: 440 k
Installed size: 1.6 M
Downloading packages:
nano-2.3.1-10.el7.x86_64.rpm                                                                           | 440 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : nano-2.3.1-10.el7.x86_64                                                                                   1/1 
  Verifying  : nano-2.3.1-10.el7.x86_64                                                                                   1/1 

Installed:
  nano.x86_64 0:2.3.1-10.el7                                                                                                  

Complete!
[root@centos7 ~]# nano /etc/selinux/config(#nano编辑配置文件)
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled(#此处模式已变)
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected. 
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

  

[root@centos7 ~]# ll anaconda-ks.cfg 
-rw-------. 1 root root 1259 Dec  3 20:30 anaconda-ks.cfg
[root@centos7 ~]# ll -Z anaconda-ks.cfg 
-rw-------. root root system_u:object_r:admin_home_t:s0 anaconda-ks.cfg

 

  

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

 ----------------------------------------------------

禁用防火墙:

systemctl disable firewalld   禁用开机启动firewalld
 systemctl enable firewalld   启用开机启动firewalld
systemctl disable --now firewalld  禁用开机启动firewalld,并立即关闭firewalld

[root@centos7 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@centos8 ~]# systemctl disable firewalld
[root@centos8 ~]# 

 

 更改文件的所有人和属组 

 1 [root@centos8 ~]# touch f1.txt(#创建文件)
 2 [root@centos8 ~]# ll(#看看列表)
 3 total 4
 4 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Desktop
 5 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Documents
 6 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Downloads
 7 -rw-r--r--  1 root root    0 Jan 17 00:06 f1.txt (#创建成功)
 8 -rw-r--r--. 1 root root 1778 Jan 11 17:12 initial-setup-ks.cfg
 9 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Music
10 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Pictures
11 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Public
12 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Templates
13 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Videos
14 [root@centos8 ~]# chown kevin f1.txt(#改变所有者属性)
15 [root@centos8 ~]# ll
16 total 4
17 drwxr-xr-x. 2 root  root    6 Jan 13 23:27 Desktop
18 drwxr-xr-x. 2 root  root    6 Jan 13 23:27 Documents
19 drwxr-xr-x. 2 root  root    6 Jan 13 23:27 Downloads
20 -rw-r--r--  1 kevin root    0 Jan 17 00:06 f1.txt
21 -rw-r--r--. 1 root  root 1778 Jan 11 17:12 initial-setup-ks.cfg
22 drwxr-xr-x. 2 root  root    6 Jan 13 23:27 Music
23 drwxr-xr-x. 2 root  root    6 Jan 13 23:27 Pictures
24 drwxr-xr-x. 2 root  root    6 Jan 13 23:27 Public
25 drwxr-xr-x. 2 root  root    6 Jan 13 23:27 Templates
26 drwxr-xr-x. 2 root  root    6 Jan 13 23:27 Videos
27 [root@centos8 ~]# chown :kevin f1.txt(#改变属组属性)
28 [root@centos8 ~]# ll
29 total 4
30 drwxr-xr-x. 2 root  root     6 Jan 13 23:27 Desktop
31 drwxr-xr-x. 2 root  root     6 Jan 13 23:27 Documents
32 drwxr-xr-x. 2 root  root     6 Jan 13 23:27 Downloads
33 -rw-r--r--  1 kevin kevin    0 Jan 17 00:06 f1.txt
34 -rw-r--r--. 1 root  root  1778 Jan 11 17:12 initial-setup-ks.cfg
35 drwxr-xr-x. 2 root  root     6 Jan 13 23:27 Music
36 drwxr-xr-x. 2 root  root     6 Jan 13 23:27 Pictures
37 drwxr-xr-x. 2 root  root     6 Jan 13 23:27 Public
38 drwxr-xr-x. 2 root  root     6 Jan 13 23:27 Templates
39 drwxr-xr-x. 2 root  root     6 Jan 13 23:27 Videos

 最后检查一下结果:所有人和组都由原来的root ,root变成了 kevin,kevin

[root@centos8 ~]# ll f1.txt
-rw-r--r-- 1 kevin kevin 0 Jan 17 00:06 f1.txt
[root@centos8 ~]#

 也可以这样改:

1 [root@centos8 ~]# ll f1.txt
2 -rw-r--r-- 1 kevin kevin 0 Jan 17 00:06 f1.txt
3 [root@centos8 ~]# chown root.bin f1.txt(#直接后面跟所有人和组,中间有个.)
4 [root@centos8 ~]# ll f1.txt
5 -rw-r--r-- 1 root bin 0 Jan 17 00:06 f1.txt
6 [root@centos8 ~]#


 范例:


 #chown --reference=f1.txt f2.txt(#像创建f1.txt那样创建f2.txt)
 1 [root@centos8 ~]# cp /etc/issue f2.txt(#创建f2)
 2 [root@centos8 ~]# ll(#列出详细,看到f2,txt已成功创建)
 3 total 8
 4 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Desktop
 5 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Documents
 6 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Downloads
 7 -rw-r--r--  1 root bin     0 Jan 17 00:06 f1.txt
 8 -rw-r--r--  1 root root   23 Jan 17 00:31 f2.txt
 9 -rw-r--r--. 1 root root 1778 Jan 11 17:12 initial-setup-ks.cfg
10 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Music
11 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Pictures
12 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Public
13 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Templates
14 drwxr-xr-x. 2 root root    6 Jan 13 23:27 Videos

 

[root@centos8 ~]# chown --re
--recursive  --reference  
[root@centos8 ~]# chown --reference=f1.txt f2.txt(#像创建f1那样创建f2)
[root@centos8 ~]# ll
total 8
drwxr-xr-x. 2 root root    6 Jan 13 23:27 Desktop
drwxr-xr-x. 2 root root    6 Jan 13 23:27 Documents
drwxr-xr-x. 2 root root    6 Jan 13 23:27 Downloads
-rw-r--r--  1 root bin     0 Jan 17 00:06 f1.txt
-rw-r--r--  1 root bin    23 Jan 17 00:31 f2.txt
-rw-r--r--. 1 root root 1778 Jan 11 17:12 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 Jan 13 23:27 Music
drwxr-xr-x. 2 root root    6 Jan 13 23:27 Pictures
drwxr-xr-x. 2 root root    6 Jan 13 23:27 Public
drwxr-xr-x. 2 root root    6 Jan 13 23:27 Templates
drwxr-xr-x. 2 root root    6 Jan 13 23:27 Videos

 

  [root@centos8 ~]# chgrp root f1.txt (#只改变属组,不改所有人)

 

[root@centos8 ~]# ll f1.txt#查看一下)
-rw-r--r-- 1 root root 0 Jan 17 00:06 f1.txt
[root@centos8 ~]# 

 

 

posted on 2021-01-16 21:34  熊猫小虾  阅读(151)  评论(0编辑  收藏  举报

导航