centos7-openssh升级到最新版本

8次阅读

共计 1841 个字符,预计需要花费 5 分钟才能阅读完成。

注意事项

本文的环境都是系统自带的 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.1
VM_0_6_centos login: testuser
Password: 
[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 openssl
openssl: /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 -V
OpenSSH_8.2p1, OpenSSL 1.0.2k-fips  26 Jan 2017

$ ls /etc/ssh
moduli  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
正文完
 0