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。

相关推荐
一心0921 小时前
ubuntu 20.04.6 sudo 源码包在线升级到1.9.17p1
运维·ubuntu·sudo·漏洞升级
好好学习啊天天向上1 小时前
世上最全:ubuntu 上及天河超算上源码编译llvm遇到的坑,cmake,ninja完整过程
linux·运维·ubuntu·自动性能优化
snoopyfly~6 小时前
Ubuntu 24.04 LTS 服务器配置:安装 JDK、Nginx、Redis。
java·服务器·ubuntu
BD_Marathon6 小时前
Ubuntu下Tomcat的配置
linux·ubuntu·tomcat
BD_Marathon6 小时前
Ubuntu:Tomcat里面的catalina.sh
linux·ubuntu·tomcat
BD_Marathon6 小时前
设置LInux环境变量的方法和区别_Ubuntu/Centos
linux·ubuntu·centos
zhaowangji7 小时前
ubuntu 20.04 安装中文输入法 (sougou pin yin)
linux·ubuntu
Maki Winster14 小时前
Peek-Ubuntu上Gif录制工具-24.04LTS可装
linux·ubuntu·peek
Maki Winster15 小时前
在 Ubuntu 下配置 oh-my-posh —— 普通用户 + root 各自使用独立主题(共享可执行)
linux·运维·ubuntu
Imagine Miracle18 小时前
Ubuntu for ARM 更换为阿里云镜像源
arm开发·ubuntu·阿里云