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。

相关推荐
zhou135284822674 小时前
Windows 配置 WSL (Ubuntu) 环境完整指南
linux·windows·ubuntu
Auv开心1 天前
Ubuntu 20.04 默认视频播放器(Totem)无法播放 MP4 文件,通常是因为缺少多媒体编解码器。以下是几种解决方法:
linux·ubuntu·音视频
指尖的爷1 天前
Ubuntu 24.04 彻底关闭自动更新(桌面+服务器通用)
服务器·数据库·ubuntu
Traveler飞1 天前
Ubuntu20.04 VMware 黑屏无法进入桌面,Ctrl+Alt+F2 可以进入终端,最终发现是磁盘空间满了
qt·ubuntu
IOT那些事儿1 天前
Ubuntu20.04虚拟机使用鼠标多功能按键
ubuntu·vmware·鼠标·xev
Uncertainty!!2 天前
Ubuntu 22.04 安装超好用中文输入法rime-ice(雾凇拼音)过程记录
linux·ubuntu·中文输入法
HAPPY酷2 天前
【ROS2】 Conda 环境搭建(命令行版)
linux·运维·python·ubuntu·机器人·conda
醉熏的石头3 天前
Ubuntu 中的编程语言(中)
linux·ubuntu·scala
bukeyiwanshui3 天前
20260622 安装配置ubuntu
linux·运维·ubuntu
AI的探索之旅3 天前
从 Ubuntu 14.04 到 24.04:TI AM335x 开发环境完整迁移与 Agent 接管方案
linux·数据库·嵌入式硬件·ubuntu·postgresql