注意事项

本文的环境都是系统自带的openssh,若是手动编译安装的,不保证成功。若是自带的,则升级过程中不需要卸载旧版本openssh。

安装之前可以先试试yum更新,若是可以更新,就不需要往下看了

# centos8 $ yum update openssh -y# 重启sshd$ systemctl restart sshd

准备工作

系统说明

  • 系统版本:CentOS Linux release 7.7.1908 (Core)
  • openssh:OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017

下载最新包

选择你需要的包下载

本文选择的是:
openssh-8.2p1.tar.gz

$ wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.2p1.tar.gz

安装telnet备用(可选)

安装新的ssh之后,只要配置好启动,就可以做到无缝切换,但是中途断开就不能连接了,为了防止这种情况,我们可以安装telnet当作备用,若是你能保证中途不会断开,此步骤可以忽略

1.安装

$ yum install telnet telnet-server -y

2.启动

$ systemctl enable telnet.socket$ systemctl start telnet.socket

3.连接

# telnet 默认禁止root用户连接,我们先生成一个普通用户 $ useradd testuser$ passwd testuser# 本地测试$ telnet 127.0.0.1VM_0_6_centos login: testuserPassword: [testuser@VM_0_6_centos ~]$ # 切换root[testuser@VM_0_6_centos ~]$ su

升级

安装所需依赖

$ yum install zlib-devel  openssl-devel  pam-devel -y

备份

$ mkdir /etc/ssh_old$ mv /etc/ssh/* /etc/ssh_old/

解压、编译安装

$ tar xzvf openssh-8.2p1.tar.gz $ cd openssh-8.2p1/# 查看openssl的位置$ whereis opensslopenssl: /usr/bin/openssl /usr/lib64/openssl /usr/include/openssl /usr/share/man/man1/openssl.1ssl.gz# 编译 --with-ssl-dir 填写上面查找的openssl路径$ ./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-ssl-dir=/usr/lib64/ --with-zlib --with-pam --with-md5-password --with-ssl-engine --with-selinux# 安装$ make && make install# 验证$  ssh -VOpenSSH_8.2p1, OpenSSL 1.0.2k-fips  26 Jan 2017$ ls /etc/sshmoduli  ssh_config  sshd_config  ssh_host_dsa_key  ssh_host_dsa_key.pub  ssh_host_ecdsa_key  ssh_host_ecdsa_key.pub  ssh_host_ed25519_key  ssh_host_ed25519_key.pub  ssh_host_rsa_key  ssh_host_rsa_key.pub

配置

1.修改sshd_config

$ vim /etc/ssh/sshd_config# 例子:配置root登录,   根据你以前的配置来PermitRootLogin yes

2.启动

# 移走以前的ssh服务, 防止与新的冲突$ mv /usr/lib/systemd/system/sshd.service /etc/ssh_old/sshd.service$ mv /usr/lib/systemd/system/sshd.socket /etc/ssh_old/sshd.socket# 在解压包中拷贝一些文件$ cp -a contrib/redhat/sshd.init /etc/init.d/sshd# 添加自启动$ chkconfig --add sshd$ chkconfig sshd on# 重新启动$ /etc/init.d/sshd restart$ systemctl daemon-reload