20220325更新:此方法同样适用于openssh8.9p1 升级。
以下原文:
openssh源代码有bug,启动后不会主动通知系统,导致系统每两分钟强杀openssh并重启。因此需要修改代码。
0.准备编译基础环境
yum -y install gcc zlib-devel openssl-devel pam-devel systemd-devel
1.下载想升级的openssh代码
2.修改源代码sshd.c,修复通知机制
a.添加
#include <systemd/sd-daemon.h>
b.找到 调用以下函数的语句
server_accept_loop(&sock_in, &sock_out, &newsock, config_s);
在前面追加
sd_notify(0, "READY=1");
3.运行下列命令生成Makefile
./configure --with-systemd --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords --with-tcp-wrappers
如运行报错显示openssl运行库找不到,那是因为旧版openssl-devel 影响。
运行
yum remove openssl-devel
即可
4.手动确认或修改Makefile
找到:
LIBS=-lcrypto -ldl -lutil -lz -lcrypt -lresolv
在后面追加内容,修改为:
LIBS=-lcrypto -ldl -lutil -lz -lcrypt -lresolv -lsystemd
5.准备如下脚本并运行:
cp -rf /etc/ssh /etc/ssh.bak
cd ./openssh-8.4p1
make
chmod 600 /etc/ssh/ssh_host_*_key
make install
sed -i '/^#PermitRootLogin/s/#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i '/^#PubkeyAuthentication/s/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config
sed -i '/^#PasswordAuthentication/s/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
sed -i '/^GSSAPIAuthentication/s/GSSAPIAuthentication/#GSSAPIAuthentication/' /etc/ssh/sshd_config
sed -i '/^GSSAPIAuthentication yes/s/GSSAPIAuthentication yes/#GSSAPIAuthentication yes/' /etc/ssh/sshd_config
sed -i '/^GSSAPICleanupCredentials/s/GSSAPICleanupCredentials/#GSSAPICleanupCredentials/' /etc/ssh/sshd_config
sed -i '/^UsePrivilegeSeparation/s/UsePrivilegeSeparation/#UsePrivilegeSeparation/' /etc/ssh/sshd_config
setenforce 0
sed -i '/^SELINUX=enforcing/s/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
service sshd restart
至此,升级完成。
参考文章有:
Ubuntu16.04或CentOS7系统下升级 openssh 到最新版
C++: undefined reference to `sd_notify’