centos7 openssh升级到最新版本

注意事项

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

安装以前能够先试试yum更新,如果能够更新,就不须要往下看了shell

# 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
  • openssl: OpenSSL 1.0.2k-fips 26 Jan 2017

下载最新包

本文选择的是:
openssh-8.2p1.tar.gz
openssl-1.1.1g.tar.gzvim

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

$ wget https://ftp.openssl.org/source/openssl-1.1.1g.tar.gz

安装telnet备用(可选)

安装新的ssh以后,只要配置好启动,就能够作到无缝切换,可是中途断开就不能链接了,为了防止这种状况,咱们能够安装telnet看成备用,如果你能保证中途不会断开,此步骤能够忽略centos

1.安装ssh

$ yum install telnet telnet-server -y

2.启动socket

$ 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

升级openssl

备份

$ mv /usr/bin/openssl /usr/bin/openssl_old

安装

$ tar xzvf openssl-1.1.1g.tar.gz
$ cd openssl-1.1.1g/
$ ./config shared && make && make install

配置软链接

$ ln -s /usr/local/bin/openssl /usr/bin/openssl

若是执行openssl version报下面的错误rest

openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

则执行下面命令解决:code

$ ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/
$ ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/

旧版本:server

$ openssl_old version
OpenSSL 1.0.2k-fips  26 Jan 2017

升级openssh

安装所需依赖

$ 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/

$ ./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/lib64/ --with-zlib --with-pam --with-md5-password --with-ssl-engine --with-selinux

# 安装
$ make && make install

# 验证
$  ssh -V
OpenSSH_8.2p1, OpenSSL 1.1.1g  21 Apr 2020

$ 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



# 从新启动
$ /etc/init.d/sshd restart
$ systemctl daemon-reload

# 添加自启动
$ chkconfig --add sshd
$ chkconfig sshd on
相关文章
相关标签/搜索