linux运维学习第十五课

来源:互联网 发布:韦德生涯总数据 编辑:程序博客网 时间:2024/05/16 10:21

#######################
########selinux
简介
#######################


#############
安全上下文#########

如果不关掉内核加强型防火强,更改本地用户家目录的话,就会因为安全上下文的问题,看不到家目录原本的文件,所以,就得对目录的安全上下文进行设置。

     systemctl disablefirewalld.service 
     systemctl stop firewalld.service
     systemctl start vsftpd
     mkdir /westos
     touch /westos/westosfile
     vim /etc/vsftpd/vsftpd.conf
     systemctl restart vsftpd
     cd /
     ll westos/
     ls -Zd westos/
     chcon -t public_content_t /westos/-R      ##
临时更改,在内核加强型防火墙 重启之后,更改作废
     ls -Zd westos/
     vim /etc/sysconfig/selinux
     reboot
     ls -Zd /westos/
     vim /etc/sysconfig/selinux
     reboot
     ls -Zd /westos/
     systemctl enable vsftpd
     semanage fcontext -l | grepwestos
     semanage fcontext -l | grep /var/ftp
     semanage fcontext -a -tpublic_content_t '/westos(/.*)?'
     semanage fcontext -l | grepwestos
     restorecon -RvvF /westos/                   ##R
递归   v显示目录  vv  显示目录及目录下的所有文件  F 刷新
     ls -Zd /westos/


*******ftp
服务赋予普通用户上传权限

没有关闭内核加强型防火墙的默认情况下它是这样的:
lftp student@172.25.254.112:~> put /etc/passwd
put: Access failed: 553 Could not create file. (passwd)
553
代表文件系统禁止这样危险的举动,除了更改配置文件之外,还必须这样更改selinux设置:
getsebool -a | grep ftp        ##
查看selinux关于ftp服务的bool
setsebool -P ftp_home_dir  on    ##
永久更改ftp普通用户家目录selinux的值 改为on

改完之后,就会发现,可以上传了。如果还不能上传,清空日志文件,查看日志文件报错
lftp student@172.25.254.112:~> put /etc/passwd
2367 bytes transferred
lftp student@172.25.254.112:~> ls
-rw-r--r--    1 1000     1000         2367 Feb 23 01:45 passwd


*********************************
内核加强型防火墙的等级:
  enforcing       ##
强制
  permissive      ##
警告
  disabled        ##
关闭

关于selinux的警告都存在/var/log/audit/audit.log
这个里面的内容被 setroubleshoot-server.x86_64  软件进行分析之后发送到  /var/log/message,并附带解决方案





##############
##############

1>diff

diff  -c #
查看更改行及其周围
      -u #
生成补丁

echo  hello world > file
echo  hello world > file1
echo  1111 >> file1

diff -u file file1 >file.path   ##
生成补丁file.path
vimdiff file file1              ##
查看两个文件的不同
patch file file.path            ##
file实行file.path补丁进行更改  得有patch软件支持
====================
[root@localhost yang]# diff -c file file1
*** file    2017-02-22 22:03:51.886061607-0500
--- file1   2017-02-22 22:04:27.948061607-0500
***************
*** 1 ****
--- 1,2 ----
  hello world
+ 1111
[root@localhost yang]# diff -u file file1
--- file    2017-02-22 22:03:51.886061607-0500
+++ file1   2017-02-22 22:04:27.948061607-0500
@@ -1 +1,2 @@
 hello world
+1111
[root@localhost yang]# diff -u file file1 >file.path
=====================




2>grep


grep -i     ##
执行不区分大小写的搜索
     -n     ##
前置返回行的行号
     -r     ##
对文件执行递归式搜索,从命名目录开始
     -c     ##
显示具有匹配模式的行的计数
     -v     ##
返回不包含模式的行


===========
cp /etc/passwd /mnt
cd /mnt
root:test:root
test:root:root
root:test:test:
ROOT:root:test
Root:test:root
添加到passwd中看效果()
=============




3>cut


cut  -d     ##
指定用于提取字段的分隔符(tab时默认值)
     -f     ##
指定要从每行中提取的字段
     -c     ##
指出要从每行中提取的文本列

============
[root@localhost yang]# cut -d : passwd -f 1,3 ##
剪切passwd中,以 : 为分隔符的第1列跟第3
root:0
bin:1
daemon:2
adm:3
lp:4
sync:5
shutdown:6
halt:7
mail:8
operator:11
games:12

[root@localhost yang]# cat passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
=============


*************************************************************************
* ifconfig eth0
只显示ip                                              *
*                                                                      *
* ifconfig eth0 | grep inet | grep inet6 -v | awk  -F " " '{ print $2}' *
* ifconfig eth0 | grep inet | grep inet6 -v | cut -d  " " -f 10         *
*************************************************************************



4>sort


sort    -n       ##
按数值而非字符排序
        -k       ##
设置排序字段 (  -k 1.2 第一个域的第二个字符串  -k  1 第一个域的第一个字符串  一般与 -t 连用)
        -t       ##
指定其他字段分隔符(默认为空格)
        -u       ##
输出时去除重复行
        -r       ##
排序改为降序
        -o       ##
输出重定向  sort file -ofile1 file排序,输出到file1中)
----------------------------

5>uniq
 

uniq   -u       ##
仅显示唯一行
       -d       ##
显示重复行
       -c       ##
每行显示一次(包括出现计数)

------------------------------
6>tr


tr  'a-z' 'A-Z'  filename   ##
文件里的内容小写换大写,输出

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

7>sed


sed   's/a/b/g'  filename   ##
把文件全文里的a替换成b
      -e 's/a/b/g'  -e 's/c/d/g'  ##
把文件全文里的a替换成bc替换成d   -e是连接
      -n 5p  filename       ##
把第5行截取出来
      5d filename           ##
删掉第5
      5p filename           ##
复制第5
      -f file1  file2       ##
file2file1里写的规则输出

cat -b file1 > file2         ##
file1加上行号放到file2





 

0 0
原创粉丝点击