首页 > 系统相关 >linux 基线检查加固

linux 基线检查加固

时间:2024-06-06 09:11:30浏览次数:12  
标签:shell vsftpd ansible task etc 基线 hosts linux 加固

修改vsftp回显信息

ansible -i hosts task -m shell -a "grep 'ftpd_banner' /etc/vsftpd/vsftpd.conf"
sed -i '/ftpd_banner/s/^/#/g' /etc/vsftpd/vsftpd.conf
ansible -i hosts task -m shell -a "echo 'ftpd_banner=" Authorized users only. All activity may be monitored and reported."' >> /etc/vsftpd/vsftpd.conf"
ansible -i hosts task -m shell -a "echo 'ftpd_banner=Authorized users only. All activity may be monitored and reported.' >> /etc/vsftpd/vsftpd.conf"
ansible -i hosts task -m shell -a "sed -i '/ftpd_banner/s/^/#/g' /etc/vsftpd/vsftpd.conf"

systemctl is-active vsftpd
systemctl reload  vsftpd
ansible -i hosts task -m shell -a "grep 'ftpd_banner' /etc/vsftpd/vsftpd.conf"

---------------------------------------------------------------------------------------------------------------------
禁止匿名FTP

ansible -i hosts task -m shell -a "systemctl is-active vsftpd"
ansible -i hosts task -m shell -a "grep 'anonymous_enable' /etc/vsftpd/vsftpd.conf"
---------------------------------------------------------------------------------------------------------------------
隐藏SSH的Banner信息

ansible -i hosts task -m shell -a "grep 'Banner' /etc/ssh/sshd_config"
ansible -i hosts task -m shell -a "cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config_bak20240605"
ansible -i hosts task -m shell -a "sed -i '/Banner/s/^/#/g' /etc/ssh/sshd_config"
ansible -i hosts task -m shell -a "systemctl reload sshd"
---------------------------------------------------------------------------------------------------------------------
修改vsftp回显信息

ansible -i hosts task -m shell -a "grep 'ftpd_banner' /etc/vsftpd/vsftpd.conf" | tee ./20240605bak/ftpd_banner.log
ansible -i hosts task -m shell -a "sed -i '/ftpd_banner/s/^/#/g' /etc/vsftpd/vsftpd.conf"
ansible -i hosts task -m shell -a "echo 'ftpd_banner=Authorized users only. All activity may be monitored and reported.' >> /etc/vsftpd/vsftpd.conf"
ansible -i hosts task -m shell -a "systemctl reload  vsftpd"
---------------------------------------------------------------------------------------------------------------------
对审计进程进行保护,防止未经授权的中断

sudo chown root:root /etc/audit/auditd.conf
sudo chmod 600 /etc/audit/auditd.conf
sudo chown root:root /etc/audit/audit.rules
sudo chmod 600 /etc/audit/audit.rules
sudo chown root:root /var/log/audit/audit.log
sudo chmod 600 /var/log/audit/audit.log

sudo systemctl restart rsyslog
sudo systemctl reload auditd
sudo systemctl start auditd
sudo systemctl status auditd
systemctl restart auditd
---------------------------------------------------------------------------------------------------------------------
日志文件读写权限

ansible -i hosts task -m shell -a " ls -la /var/log | grep -E 'messages$|secure$|maillog$|cron$|spooler$|boot.log$' "
ansible -i hosts task -m shell -a "chmod 600 /var/log/messages"
ansible -i hosts task -m shell -a "chmod 600 /var/log/secure"
ansible -i hosts task -m shell -a "chmod 600 /var/log/maillog"
ansible -i hosts task -m shell -a "chmod 600 /var/log/cron"
ansible -i hosts task -m shell -a "chmod 600 /var/log/spooler"
ansible -i hosts task -m shell -a "chmod 600 /var/log/boot.log"
---------------------------------------------------------------------------------------------------------------------
限制具备超级管理员权限的用户远程登录
ansible -i hosts task -m shell -a " grep 'PermitRootLogin' /etc/ssh/sshd_config  | grep -Ev '^#|^$' "
ansible -i hosts task -m shell -a "sed -i '/PermitRootLogin/s/^/#/g' /etc/ssh/sshd_config"
ansible -i hosts task -m shell -a "echo 'PermitRootLogin no' >> /etc/ssh/sshd_config"
ansible -i hosts task -m shell -a "systemctl reload sshd"

ansible -i hosts task -m shell -a "service sshd reload"
/sbin/service sshd reload


---------------------------------------------------------------------------------------------------------------------
隐藏Telnet的Banner信息

ansible -i hosts task -m shell -a " cat /etc/issue.net "
ansible -i hosts task -m shell -a " cp -p /etc/issue.net /etc/issue.net_bak "
ansible -i hosts task -m shell -a "echo 'Authorized users only. All activity may be monitored and reported' > /etc/issue.net"
---------------------------------------------------------------------------------------------------------------------
Vsftp的chroot list配置

ansible -i hosts task -m shell -a " grep 'chroot_local_user' /etc/vsftpd/vsftpd.conf  | grep -Ev '^#|^$' "
ansible -i hosts task -m shell -a " ll -ls /etc/vsftpd/chroot_list "
ansible -i hosts task -m shell -a "echo 'postgres' >> /etc/vsftpd/chroot_list"
ansible -i hosts task -m shell -a " cat /etc/vsftpd/chroot_list "
---------------------------------------------------------------------------------------------------------------------
Wuftp的banner信息

ansible -i hosts task -m shell -a "echo 'banner /thisftpbannerfile' >>/etc/ftpaccess"
ansible -i hosts task -m shell -a "touch /thisftpbannerfile"
ansible -i hosts task -m shell -a "echo 'this is banner' >>/thisftpbannerfile"
---------------------------------------------------------------------------------------------------------------------
定时账户自动登出
ansible -i hosts task -m shell -a " grep 'TMOUT' /etc/profile  | grep -Ev '^#|^$' "
---------------------------------------------------------------------------------------------------------------------

检查密码长度及复杂度策略
ansible -i hosts task -m shell -a " grep -E '(ucredit=-1)|(lcredit=-1)|(ocredit=-1)|(dcredit=-1)' /etc/pam.d/system-auth"
---------------------------------------------------------------------------------------------------------------------
对系统账号进行登录限制

---------------------------------------------------------------------------------------------------------------------
检查是否指定用户组成员使用su命令

ansible -i hosts task -m shell -a "grep 'wheel' /etc/pam.d/su | grep -Ev '^#|^$' "
---------------------------------------------------------------------------------------------------------------------
日志文件读写权限640

ansible -i hosts task -m shell -a " ls -la /var/log | grep -E 'messages$|secure$|maillog$|cron$|spooler$|boot.log$' "
---------------------------------------------------------------------------------------------------------------------
设置FTP权限及访问,限制部分用户的ftp访问权限

ansible -i hosts task -m shell -a "cat /etc/ftpaccess "
---------------------------------------------------------------------------------------------------------------------
重要目录和文件的权限进行设置
0440
0644
ansible -i hosts task -m shell -a "ls -lt /etc/shadow /etc/passwd  /etc/group "
ansible -i hosts task -m shell -a "chmod 0600 /etc/shadow && chmod 0644  /etc/passwd && chmod 0644 /etc/group "
---------------------------------------------------------------------------------------------------------------------
账户口令安全符合要求90

ansible -i hosts task -m shell -a "cat /etc/login.defs | grep PASS_MAX_DAYS"
---------------------------------------------------------------------------------------------------------------------
检查新建用户的home目录的缺省访问权限027

ansible -i hosts task -m shell -a "cat /etc/login.defs | grep UMASK "
---------------------------------------------------------------------------------------------------------------------
配置记录cron行为日志功能

cat  /etc/rsyslog.conf /etc/syslog.conf /etc/rsyslog.d/50-default.conf /etc/syslog-ng/syslog-ng.conf | grep cron
---------------------------------------------------------------------------------------------------------------------
对用户登录认证、权限变更进行记录

(cat /etc/rsyslog.conf;cat /etc/syslog.conf;cat /etc/rsyslog.d/50-default.conf;cat /etc/syslog-ng/syslog-ng.conf) | grep -Ev '^#|^$'|  grep -E '^authpriv|^authpriv.info|^filter'
---------------------------------------------------------------------------------------------------------------------

  

标签:shell,vsftpd,ansible,task,etc,基线,hosts,linux,加固
From: https://www.cnblogs.com/libin-linux/p/18234400

相关文章

  • 【Linux】进程(6):环境变量
    大家好,我是苏貝,本篇博客带大家了解Linux进程(6):环境变量,如果你觉得我写的还不错的话,可以给我一个赞......
  • 2024年6月 AWVS -24.4.27详细安装教程附下载教程含windows和linux多版本
    免责声明请勿利用文章内的相关技术从事非法测试。由于传播、利用此文所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,作者不为此承担任何责任,请务必遵守网络安全法律法规。本文仅用于测试,请完成测试后24小时删除,请勿用于商业用途。如文中内容涉及侵权......
  • Linux 安装 docker-compose
    什么是DockerComposeDockerCompose是一个单独的开源项目,DockerCompose可以高效管理和定义多个容器作用:批量容器编排web服务、redis、mysql、nginx等等多个容器docker-compose.ymlversion:'3.1'services:web:build:.ports:-"5000:5000"volumes:-.:/code-......
  • 【Linux多线程】线程的终止、等待和分离
    文章目录线程终止正常退出return退出pthread_exit函数终止线程pthread_cancel强制终止线程进程终止线程等待为什么需要等待线程?pthread_join函数分离线程pthread_detach函数线程终止下面给出终止线程的三种方式:正常退出:线程执行完它的函数之后return自动结......
  • 新手上路:Linux虚拟机创建与Hadoop集群配置指南①(未完)
    一、基础阶段Linux操作系统:创建虚拟机1.创建虚拟机打开VM,点击文件,新建虚拟机,点击自定义,下一步下一步这里可以选择安装程序光盘映像文件,我选择稍后安装选择linux系统位置不选C盘,创建一个新的文件夹VM来放置虚拟机,将虚拟机名字改为master方便后续识别(也可以改为其他......
  • linux信号集与信号掩码-保护信号处理程序,确保进程正确运行
    在Linux环境下,当进程收到信号时,如何优雅地处理并确保程序的正常运行?这就需要借助信号集和信号掩码的功能。本文将为你揭开信号集和信号掩码的神秘面纱,并通过生动的代码示例,让你彻底掌握在C++程序中使用它们的技巧。一、信号集:表示信号的数据结构信号集(signalset)是......
  • 【Linux】(六)—— vim编辑器
    vim文件编辑器Vim(ViImproved)是一个高度可配置的文本编辑器,最初基于UNIX下的Vi编辑器发展而来,广泛用于程序开发和系统管理中。vim编辑器可以只通过终端命令即可编写修改文件,不需要和gedit一样需要打开类似于记事本的窗口。Vim以其高效、灵活和强大著称,但对初学者来说可能有......
  • Linux基础 (十四):socket网络编程
         我们用户是处在应用层的,根据不同的场景和业务需求,传输层就要为我们应用层提供不同的传输协议,常见的就是TCP协议和UDP协议,二者各自有不同的特点,网络中的数据的传输其实就是两个进程间的通信,两个进程在通信时,传输层使用TCP协议将一方进程的应用层的数据传输给另一......
  • Linux基础 (十三):计算机网络基础概论
    一、网络基本概念1.1网络    把独立自主的计算机通过传输介质和网络设备链接起来,就构成一个网络,网络是由若干结点和连接这些结点的链路组成,网络中的结点可以是计算机,交换机、路由器等设备。网络设备有:交换机、路由器、集线器传输介质有:双绞线、同轴电缆、光纤......
  • Linux容器架构
    1.Iaas:基础设施即服务Infrastructure-as-a-ServicePaas:平台即服务Platform-as-a-ServiceSaas:软件即服务Software-as-a-ServiceCaas:容器即服务介于IAAS和PAASIAAS,PAAS,SAAS这些服务,用于帮助人们更快实现目标(搭建环境,使用产品)从左到右,人们需要管理与维护的地方......