Loading... ![OpenSSH.png](/usr/uploads/2021/08/3883382850.png) # 1、安装Telnet服务端(可选) 如果是远程SSH升级,建议使用Telnet远程连接进行升级,如果你对升级过程比较有把握可以不使用Telnet直接SSH。 # 2、安装依赖软件包 ```bash yum install wget gcc zlib-devel openssl-devel pam-devel libselinux-devel zlib-devel openssl-devel -y ``` # 3、卸载系统自带的openssh 查看 ```bash rpm -qa | grep ssh ``` 卸载 ```bash rpm -e `rpm -qa|grep openssh` --nodeps ``` # 4、下载新版OpenSSh并安装 先自行查询所需的OpenSSH版本号,将下面的${version}替换成自己所需的版本号,另外wget后面的地址也可以替换成其它的CDN地址。 ```bash wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${version}.tar.gz tar -zxvf openssh-${version}.tar.gz cd openssh-${version} ./configure ``` 如果报错缺少组件,可使用yum安装缺少的组件后再次执行configure ```bash make make install ``` # 5、拷贝源文件 ```bash cp contrib/redhat/sshd.init /etc/init.d/sshd cp contrib/redhat/sshd.pam /etc/pam.d/sshd.pam chmod +x /etc/init.d/sshd ``` # 6、修改/etc/init.d/sshd中的SSHD路径 ```bash vim /etc/init.d/sshd ``` 修改以下内容 ``` SSHD=/usr/local/sbin/sshd ``` # 7、修改sshd配置文件 ```bash vim /usr/local/etc/sshd_config ``` 加入以下内容 ``` PermitRootLogin yes KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group1-sha1,curve25519-sha256@libssh.org ``` # 8、将sshd指令追加到Path ```bash `export PATH=$PATH:/usr/local/sbin` ``` # 9、建立文件夹映射 这一步主要是为了日后配置方便,比如说宝塔之类的面板,升级OpenSSH后会导致宝塔面板没法正常修改SSH相关设置。 ```bash ln -s /usr/local/etc /etc/ssh ``` # 10、添加自启服务SSH到开机启动项 ```bash chkconfig --add sshd chkconfig sshd on ``` # 11、重启sshd服务 ```bash systemctl daemon-reload systemctl restart sshd ``` # 12、查看OpenSSH版本 如果你是通过SSH远程连接的方式升级的话得先重新连接一下才会生效。 ```bash ssh -V ``` Last modification:November 6, 2024 © Allow specification reprint Support Appreciate the author AliPayWeChat Like If you think my article is useful to you, please feel free to appreciate