Ubuntu16.04升级openssh-9.8p1

7月1日OpenSSH官方发布安全更新,忙着处理的同时记录一下升级过程。

系统环境

复制代码
root@NServer:~# cat /proc/version
Linux version 3.4.113-sun8i (root@test) (gcc version 5.5.0 (Linaro GCC 5.5-2017.10) ) #40 SMP PREEMPT Tue Mar 16 14:24:14 CST 2021
root@NServer:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.7 LTS
Release:	16.04
Codename:	xenial

安装包

复制代码
zlib-1.3.1.tar.gz         # https://www.zlib.net/
openssl-1.1.1w.tar.gz     # https://www.openssl.org/source/old/1.1.1/index.html
openssh-9.8p1.tar.gz      # https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/

升级步骤

升级顺序

openssl -> zlib -> openssh

安装openssl

复制代码
tar zxvf openssl-1.1.1w.tar.gz
cd openssl-1.1.1w
./config --prefix=/usr/local/openssl shared
make 
make install
#创建软连接
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib/
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib/
#查看openssl版本,能正常输出版本号表示成功
/usr/local/openssl/bin/openssl version

安装zlib

复制代码
tar zxvf zlib-1.3.1.tar.gz
cd zlib-1.3.1
./configure --prefix=/usr/local/zlib
make
make install

安装openssh

复制代码
#先卸载原openssh,卸载后切记不要断开ssh连接
sudo apt purge --remove "openssh*"
rm -rf /usr/local/openssh
#安装openssh
tar zxvf openssh-9.8p1.tar.gz
cd openssh-9.8p1
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/zlib --without-openssl-header-check 
make 
make install

配置openssh

重启sshd服务会提示"Privilege separation user sshd does not exist"需要再/etc/passwd最后加入一行sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

复制代码
echo 'sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin' >> /etc/passwd

注册为服务,创建sshd.service文件

复制代码
vim /usr/lib/systemd/system/sshd.service

写入内容:

复制代码
[Unit]
Description=OpenSSH serve
Documentation=man:sshd(8) man:sshd_config(5)
#After=network.target sshd-keygen.service
#Wants=sshd-keygen.service
After=network.target

[Service]
#Type=notify
#EnvironmentFile=/etc/sysconfig/sshd
#ExecStart=/usr/local/openssh/sbin/sshd -D $OPTIONS
ExecStart=/usr/local/openssh/sbin/sshd
#ExecReload=/bin/kill -HUP $MAINPID
#KillMode=process
#Restart=on-failure
#RestartSec=42s

[Install]
WantedBy=multi-user.target

重载Systemctl,并设置为自启动

复制代码
systemctl daemon-reload
systemctl restart sshd

这里会启动失败,使用systemctl status sshd查看失败原因,是因为原ssh服务占用了22端口,所以这里先把新的ssh服务修改成8022

复制代码
vim /etc/ssh/sshd_config

把Port和ListenAddress 0.0.0.0前面的#号去掉,并把Port 后面的22改成8022如下图所示:

同时需要将8022加入防火墙,否则ssh无法连接

复制代码
ufw allow 8022

改完后保存,继续重启sshd

复制代码
systemctl restart sshd

没报错后,查看sshd状态,Active: active (running) 表示运行中,此时可以使用putty等工具通过8022端口登录服务器。

复制代码
systemctl status sshd

加入开机启动

复制代码
systemctl enable sshd

如果提示"update-rc.d: error: sshd Default-Start contains no runlevels, aborting.",需要修改sshd

复制代码
vim /etc/init.d/sshd

在#!/bin/bash 下面第二行插入

复制代码
### BEGIN INIT INFO
# Provides:          sshd
# Required-Start:
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start sshd daemon at boot time
# Description:       Start sshd daemon at boot time
### END INIT INFO

如下图所示:

保存后重新设置开机自启:

复制代码
systemctl enable sshd

成功后如下图所示:

在/etc/ssh/sshd_config末尾追加三行数据

复制代码
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config
echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config

重启服务器:

复制代码
reboot

#查看版本:

复制代码
ssh -V

至此升级成功!

附:记得将ssh端口改回22。

相关推荐
逢生博客18 小时前
Ubuntu Server 快速部署长安链:基于 Go 的智能合约实现商品溯源
ubuntu·golang·区块链·智能合约·web3.0·长安链·商品溯源
blasit19 小时前
Ubuntu 20.04.6交叉编译得到Ubuntu 16.04.6的可执行文件
linux·运维·ubuntu
满目8281 天前
【Ubuntu系统实战】一站式部署与管理MySQL、MongoDB、Redis三大数据库
数据库·redis·mysql·mongodb·ubuntu·数据库布置
软件测试大叔1 天前
ubuntu替换源为阿里源(修改ubuntu.source文件)
linux·运维·ubuntu
政安晨2 天前
Ubuntu 服务器无法 ping 通网站域名的问题解决备忘 ——通常与网络配置有关(DNS解析)
linux·运维·服务器·ubuntu·ping·esp32编译服务器·dns域名解析
程序员 _孜然3 天前
Ubuntu/Debian修改网卡名字enP3p49s0为eth0
linux·运维·驱动开发·嵌入式硬件·ubuntu·debian
可期不折腾3 天前
NVIDIA Nsight Systems性能分析工具
ubuntu·nvidia·nsight systems·性能分析工具
Fireworkitte4 天前
Ubuntu 系统 tar 包源码安装 Nginx
linux·nginx·ubuntu
ElendaLee4 天前
笔记本电脑Windows+Ubuntu 双系统,Ubuntu无法挂载Windows的硬盘 报错问题解决
linux·运维·ubuntu
QtSeeker4 天前
Ubuntu22.04安装VMware Tools
linux·ubuntu