1. #!/bin/bash
    2. # 安装编译环境
    3. yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam pam-devel
    4. # 【openssl】
    5. # 备份当前openssl
    6. mv /usr/bin/openssl /usr/bin/openssl_bak
    7. mv /usr/include/openssl /usr/include/openssl_bak
    8. # 编译安装openssl
    9. tar xf openssl-1.0.2u.tar.gz
    10. cd openssl-1.0.2u
    11. ./config shared && make && make install
    12. # 创建软连接
    13. ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
    14. ln -s /usr/local/ssl/include/openssl /usr/include/openssl
    15. # 加载新配置
    16. echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
    17. /sbin/ldconfig
    18. # 查看当前openssl 版本
    19. openssl version
    20. cd ..
    21. # 【openssh】
    22. # 编译安装
    23. tar xf openssh-8.8p1.tar.gz
    24. cd openssh-8.8p1
    25. ./configure --prefix=/usr/local/myssh_8.8p1 \
    26. --sysconfdir=/usr/local/myssh_8.8p1/ssh \
    27. --with-openssl-includes=/usr/local/ssl/include \
    28. -with-ssl-dir=/usr/local/ssl \
    29. --with-privsep-user=sshd --with-zlib \
    30. --with-pam \
    31. --with-md5-passwords
    32. make && make install
    33. # 备份openssh
    34. mv /etc/init.d/sshd /etc/init.d/sshd.bak
    35. mv /usr/sbin/sshd /usr/sbin/sshd.bak
    36. mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
    37. mv /etc/ssh/sshd_config /etc/ssh/sshd_config.bak_`date '+%Y%m%d'`
    38. # 创建软连接
    39. ln -s /usr/local/myssh_8.8p1/sbin/sshd /usr/sbin/sshd
    40. ln -s /usr/local/myssh_8.8p1/ssh/sshd_config /etc/ssh/sshd_config
    41. # 复制sshd启动脚本
    42. cp -a contrib/redhat/sshd.init /etc/init.d/sshd
    43. cp -a /usr/local/myssh_8.8p1/bin/ssh-keygen /usr/bin/ssh-keygen
    44. # 允许root用户远程连接
    45. sed -i '20a PermitRootLogin yes' /usr/local/myssh_8.8p1/ssh/sshd_config
    46. # 避开绿盟安全扫描
    47. echo "Protocol 2" >> /usr/local/myssh_8.8p1/ssh/sshd_config
    48. echo "Banner /etc/ssh_banner" >> /usr/local/myssh_8.8p1/ssh/sshd_config
    49. # 设置对旧版本支持的算法,否则会报错no hostkey algno
    50. echo "HostKeyAlgorithms=+ssh-rsa,ssh-dss" >> /usr/local/myssh_8.8p1/ssh/sshd_config
    51. # 禁止dns解析
    52. sed -i 's/#UseDNS no/UseDNS no/g' /usr/local/myssh_8.8p1/ssh/sshd_config
    53. #
    54. chkconfig sshd on
    55. #service sshd restart
    56. #sed -i 's/PermitRootLogin yes/PermitRootLogin no/g' /usr/local/myssh_8.8p1/ssh/sshd_config