#!/bin/bash
#
# 准备编译环境
apt-get install libpam0g-dev gcc zlib1g-dev -y
# 【openssl】
# 备份当前openssl
mv /usr/bin/openssl /usr/bin/openssl_bak
mv /usr/include/openssl /usr/include/openssl_bak
# 编译安装openssl
tar xf openssl-1.0.2u.tar.gz
cd openssl-1.0.2u
./config shared && make && make install
# 创建软连接
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
# 加载新配置
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
/sbin/ldconfig
# 查看当前openssl 版本
openssl version
cd ..
# 【openssh】
# 编译安装
tar xf openssh-8.8p1.tar.gz
cd openssh-8.8p1
./configure --prefix=/usr/local/myssh_8.8p1 \
--sysconfdir=/usr/local/myssh_8.8p1/ssh \
--with-openssl-includes=/usr/local/ssl/include \
-with-ssl-dir=/usr/local/ssl \
--with-privsep-user=sshd --with-zlib \
--with-pam \
--with-md5-passwords \
--without-openssl-header-check
make && make install
# 备份openssh
mv /etc/init.d/sshd /etc/init.d/sshd.bak
mv /usr/sbin/sshd /usr/sbin/sshd.bak
mv /etc/ssh/sshd_config /etc/ssh/sshd_config.bak_`date '+%Y%m%d'`
# 创建软连接
ln -s /usr/local/myssh_8.8p1/sbin/sshd /usr/sbin/sshd
ln -s /usr/local/myssh_8.8p1/ssh/sshd_config /etc/ssh/sshd_config
#
sed -i '20a PermitRootLogin yes' /usr/local/myssh_8.8p1/ssh/sshd_config
# 避开绿盟安全扫描
echo "Protocol 2" >> /usr/local/myssh_8.8p1/ssh/sshd_config
echo "Banner /etc/ssh_banner" >> /usr/local/myssh_8.8p1/ssh/sshd_config
# systemctl restart sshd