1. #!/bin/bash
    2. # 安装编译环境
    3. yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam* zlib*
    4. # 【openssl】
    5. # 编译安装openssl
    6. wget --no-check-certificate https://www.openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz
    7. tar xf openssl-1.0.2u.tar.gz
    8. cd openssl-1.0.2u
    9. ./config shared && make && make install
    10. # 备份当前openssl
    11. mv /usr/bin/openssl /usr/bin/openssl_bak
    12. mv /usr/include/openssl /usr/include/openssl_bak
    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. wget https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/openssh-8.9p1.tar.gz
    25. tar xf openssh-8.9p1.tar.gz
    26. cd openssh-8.9p1
    27. ./configure --prefix=/usr/local/myssh_8.9p1 \
    28. --sysconfdir=/usr/local/myssh_8.9p1/ssh \
    29. --with-openssl-includes=/usr/local/ssl/include \
    30. -with-ssl-dir=/usr/local/ssl \
    31. --with-privsep-user=sshd --with-zlib \
    32. --with-pam
    33. make && make install
    34. # 备份openssh
    35. mv /etc/init.d/sshd /etc/init.d/sshd.bak_`date '+%Y%m%d'`
    36. mv /usr/sbin/sshd /usr/sbin/sshd.bak_`date '+%Y%m%d'`
    37. mv /etc/ssh/sshd_config /etc/ssh/sshd_config.bak_`date '+%Y%m%d'`
    38. # 创建软连接
    39. ln -s /usr/local/myssh_8.9p1/sbin/sshd /usr/sbin/sshd
    40. ln -s /usr/local/myssh_8.9p1/ssh/sshd_config /etc/ssh/sshd_config
    41. # 复制sshd启动脚本
    42. cp contrib/redhat/sshd.init /etc/init.d/sshd
    43. # 允许root用户远程连接
    44. # sed -i '20a PermitRootLogin yes' /usr/local/myssh_8.9p1/ssh/sshd_config
    45. # 避开绿盟安全扫描
    46. echo "Protocol 2" >> /usr/local/myssh_8.9p1/ssh/sshd_config
    47. echo "Banner /etc/ssh_banner" >> /usr/local/myssh_8.9p1/ssh/sshd_config
    48. # 禁止dns解析
    49. sed -i 's/#UseDNS no/UseDNS no/g' /usr/local/myssh_8.9p1/ssh/sshd_config
    50. # 不移走的话影响启动
    51. mv /usr/lib/systemd/system/sshd.service /root/
    52. chkconfig sshd on
    53. # 重启sshd
    54. systemctl restart sshd
    55. # sed -i 's/PermitRootLogin yes/PermitRootLogin no/g' /usr/local/myssh_8.9p1/ssh/sshd_config
    56. sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /usr/local/myssh_8.9p1/ssh/sshd_config
    57. #