当前位置:网站首页>Batch update software and security optimization (taking openssh as an example) -- the road of building a dream
Batch update software and security optimization (taking openssh as an example) -- the road of building a dream
2022-04-22 10:32:00 【The road of building dreams】
Use ansible Batch update openssh
Environmental statement :
Multiple machines , such as 500 platform
Network interworking in LAN
One of them is installed with ansible, And can connect all other machines
The operating system version is consistent , It's all here centos7
1. To write hosts file , For example, three sets
[test]
192.168.1.30 ansible_ssh_user=root ansible_ssh_password=root ansible_ssh_port=22
[dev]
192.168.1.60 ansible_ssh_user=root ansible_ssh_password=root ansible_ssh_port=22
[prod]
192.168.1.100 ansible_ssh_user=root ansible_ssh_password=root ansible_ssh_port=22
2. Distribute the upgraded offline installation package to each host
ansible all -i hosts -m copy -a "src=/root/openssh9.0p1.tar.gz dest=/root/"
3. Perform decompression and cleanup
ansible all -i hosts -m shell -a "tar -zxf /root/openssh9.0p1.tar.gz -C /root/ && rm -rf /root/openssh9.0p1.tar.gz"
4. Back up existing configuration and permission files
ansible all -i hosts -m shell -a "cp -rp /etc/ssh /etc/ssh_backup_$(date +'%Y-%m-%d_%H%M%S')"
ansible all -i hosts -m shell -a "cp -rp /etc/pam.d/sshd /etc/pam.d/sshd_backup_$(date +'%Y-%m-%d_%H%M%S')"
5. Perform upgrade operation in groups , Avoid mistakes caused by a shuttle
ansible test -i hosts -m shell -a "cd /root/openssh9.0p1 && yum localinstall -y ./openssh*.rpm"
ansible test -i hosts -m shell -a "cat /root/openssh9.0p1/sshd > /etc/pam.d/sshd"
--- episode
ansible test -i hosts -m shell -a "chmod 400 /etc/ssh/ssh_host_* && echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config && echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config"
ansible test -i hosts -m shell -a "sed -i 's/#Port/Port/' /etc/ssh/sshd_config && sed -i '/Port/a Port 18822' /etc/ssh/sshd_config"
---
ansible test -i hosts -m shell -a "systemctl restart sshd && systemctl enable sshd"
6. Verify the upgraded version
ansible all -i hosts -m shell -a "ssh -V"
ansible all -i hosts -m shell -a "rpm -qa | grep openssh"
ansible all -i hosts -m shell -a "ss -anlp | grep :18822"
matters needing attention :
--- There is no consideration here selinux The situation of , So it's best to do this before , Yes selinux disabled
--- The firewall is not considered here , So it's best to do this before , Yes firewalld stop disable
--- The upgrade uses root Account , Not considering the situation of other users , It needs to be modified according to the actual situation
--- Here we use openssh Batch upgrade example , Using offline rpm package , Other software upgrades need to be based on actual scenarios , According to the actual situation .
consider selinux and firewalld The situation of , Conduct ssh Service security optimization
Be careful : In this case, you need to add a port first 18822, Only when the test connection is OK can the default 22 port
# Add port
ansible all -i hosts -m shell -a "sed -i "s/\#Port 22/Port 22/g" /etc/ssh/sshd_config"
ansible all -i hosts -m shell -a "sed -i '/\Port 22/a Port 18822' /etc/ssh/sshd_config"
# Check firewall status
ansible all -i hosts -m shell -a "systemctl status firewalld"
# Open ports
ansible all -i hosts -m shell -a "firewall-cmd --zone=public --add-port=18822/tcp --permanent && firewall-cmd --reload"
# Inquire about
ansible all -i hosts -m shell -a "firewall-cmd --zone=public --query-port=18822/tcp"
# see selinux state Enforcing Turn on ,disabled close ,permissive Close but log warning messages
ansible all -i hosts -m shell -a "getenforce"
# Inquire about ssh port
ansible all -i hosts -m shell -a "semanage port -l|grep ssh"
# add to ssh Port discharge
ansible all -i hosts -m shell -a "semanage -a -t ssh_port_t -p tcp 18822"
# Check again ssh port
ansible all -i hosts -m shell -a "semanage port -l|grep ssh"
# restart ssh service
ansible all -i hosts -m shell -a "systemctl restart sshd"
# View port monitoring
ansible all -i hosts -m shell -a "ss -anlp | grep :18822"
# Test connection You can write one here shell Script for batch detection
ssh -v -p 18822 root@ip
# close 22
ansible all -i hosts -m shell -a "sed -i 's/^Port 22/^#&/g' /etc/ssh/sshd_config"
perhaps
ansible all -i hosts -m shell -a "sed -i "s/\Port 22/#Port 22/g" /etc/ssh/sshd_config"
ansible all -i hosts -m shell -a "systemctl restart sshd"
Related offline packages and files :openssh9.0p1.tar.gz- System security document class resources -CSDN download
版权声明
本文为[The road of building dreams]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221025021859.html
边栏推荐
- 【SQL server速成之路】数据库的查询
- VMware virtual machine download and installation tutorial
- 【sv】 assign force区别
- 【FAQ】HMS Core推送服务与本地创建通知消息如何相互覆盖?
- Here comes the article ~ share compressed and decompressed files [online website]
- 信息论小结(一)
- Swoole high performance in memory database use and configuration tutorial
- Directory of message queuing Master Course
- QT record of some problems in signal slot connection
- TC397 EVADC
猜你喜欢

soatest初步认识

企业级 Web 开发的挑战
![[leetcode] the first mock exam of two tree traversal iteration method.](/img/2a/4fb0de0f001738729a0051c14a1e5d.jpg)
[leetcode] the first mock exam of two tree traversal iteration method.

三分钟快速了解互动涂鸦

【leetcode】94. Middle order traversal of binary tree

【SQL server速成之路】数据库的查询

Pytorch semantic segmentation total convolution network

Film online ticket purchase system based on SSM

QT record of some problems in signal slot connection

【leetcode】94.二叉树的中序遍历
随机推荐
Film online ticket purchase system based on SSM
Google Adsense suggests that the advertising capture tool is wrong, which may lead to reduced revenue. What should we do
build perl from source
绿色节能建筑已是大势所趋
项目如何解决跨域问题
MySQL进阶之表的增删改查
2022-04-19_ Function (II)
matlab的解决反复激活问题的license.lic文件
CISSP认证每日知识点(2022年4月21日)
Async function
MySQL basic collection
谷歌开发者工具preserve log
How does Oracle use circular control keywords exit, goto, continue
build perl from source
The debug breakpoint of idea thread pool cannot jump in
【uvm】 raise_objection之前不能加入消耗仿真时间的语句
Cobbler cobbler cobbler
企业级 Web 开发的挑战
机器人系统设计-coppeliasim仿真
golang time strings常用方法