Centos8 升级 OpenSSH

  1. 在国内镜像找到需要的版本号:阿里云

    cd /usr/local/src
    sudo wget https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/openssh-9.8p1.tar.gz
  2. 解压文件夹

    sudo tar zxvf openssh-9.8p1.tar.gz
    sudo rm openssh-9.8p1.tar.gz 
  3. 安装依赖

    sudo yum install pam-devel krb5-devel zlib-devel openssl-devel
  4. --help查看相关支持 ./configure 进行配置

    cd openssh-9.8p1/
    ./configure --help
    # sysconfdir 修改默认配置文件夹 --prefix修改文件安装目录
    ./configure --prefix=/usr/local/openssh9.8 --sysconfdir=/etc/ssh --with-pam --with-kerberos5
  5. 备份相关文件夹和文件防止升级失败

    sudo mv /etc/ssh /etc/ssh.bak
    sudo mv /usr/sbin/sshd /usr/sbin/sshd.bak
    sudo mv /usr/bin/ssh /usr/bin/ssh.bak
    sudo mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
    sudo mv /lib/systemd/system/sshd.service /lib/systemd/system/sshd.service-bak 
  6. 编译安装、复制文件、参考就配置、修改新配置

    sudo make
    sudo make install
    sudo cp -rf /usr/local/openssh9.8/sbin/sshd /usr/sbin/sshd
    sudo cp -rf /usr/local/openssh9.8/bin/ssh /usr/bin/ssh 
    sudo cp -rf /usr/local/openssh9.8/bin/ssh-keygen /usr/bin/ssh-keygen
    sudo cat /etc/ssh.bak/sshd_config 
    sudo vim /etc/ssh/sshd_config 
  7. 重启服务

    sudo systemctl stop sshd.service
    sudo systemctl daemon-reload
    sodo cp /usr/local/src/openssh-9.8p1/contrib/redhat/sshd.init /etc/init.d/sshd
    /etc/init.d/sshd restart
    sudo /etc/init.d/sshd restart
  8. 另开窗口检测是否能顺利链接

    ssh xxx@xxx
  9. 配置开机启动

    sudo systemctl status sshd
    sudo chkconfig --add  sshd
    sudo chkconfig --list sshd
  10. 命令行检测是否成功

    ssh -V
    sshd -V
Last modification:January 17, 2025
如果觉得我的文章对你有用,请收藏本站