1. #!/bin/bash
    2. #
    3. # 准备编译环境
    4. apt-get install libpam0g-dev gcc zlib1g-dev -y
    5. # 【openssl】
    6. # 备份当前openssl
    7. mv /usr/bin/openssl /usr/bin/openssl_bak
    8. mv /usr/include/openssl /usr/include/openssl_bak
    9. # 编译安装openssl
    10. tar xf openssl-1.0.2u.tar.gz
    11. cd openssl-1.0.2u
    12. ./config shared && make && make install
    13. # 创建软连接
    14. ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
    15. ln -s /usr/local/ssl/include/openssl /usr/include/openssl
    16. # 加载新配置
    17. echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
    18. /sbin/ldconfig
    19. # 查看当前openssl 版本
    20. openssl version
    21. cd ..
    22. # 【openssh】
    23. # 编译安装
    24. tar xf openssh-8.8p1.tar.gz
    25. cd openssh-8.8p1
    26. ./configure --prefix=/usr/local/myssh_8.8p1 \
    27. --sysconfdir=/usr/local/myssh_8.8p1/ssh \
    28. --with-openssl-includes=/usr/local/ssl/include \
    29. -with-ssl-dir=/usr/local/ssl \
    30. --with-privsep-user=sshd --with-zlib \
    31. --with-pam \
    32. --with-md5-passwords \
    33. --without-openssl-header-check
    34. make && make install
    35. # 备份openssh
    36. mv /etc/init.d/sshd /etc/init.d/sshd.bak
    37. mv /usr/sbin/sshd /usr/sbin/sshd.bak
    38. mv /etc/ssh/sshd_config /etc/ssh/sshd_config.bak_`date '+%Y%m%d'`
    39. # 创建软连接
    40. ln -s /usr/local/myssh_8.8p1/sbin/sshd /usr/sbin/sshd
    41. ln -s /usr/local/myssh_8.8p1/ssh/sshd_config /etc/ssh/sshd_config
    42. #
    43. sed -i '20a PermitRootLogin yes' /usr/local/myssh_8.8p1/ssh/sshd_config
    44. # 避开绿盟安全扫描
    45. echo "Protocol 2" >> /usr/local/myssh_8.8p1/ssh/sshd_config
    46. echo "Banner /etc/ssh_banner" >> /usr/local/myssh_8.8p1/ssh/sshd_config
    47. # systemctl restart sshd