一、准备工作

首先确认升级方案,即双版本方案和替换方案。
双版本方案:2个版本ssh同时存在,监听不同的端口,使用不同的配置文件。
替换方案:新版本替换老版本,二进制文件升级为新版本,配置文件仍使用老版本。

程序名称版本号依赖
openssh10.0p2openssl1.1.1w

1.1 环境检查

1.1.1 查看当前openssl版本
[root@localhost ~]# openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017
1.1.2 查看当前openssh版本
[root@localhost ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017

1.2 依赖安装

有公网

#全量依赖
yum groupinstall "Development Tools" -y
yum install wget openssl-devel zlib-devel pam-devel krb5-devel libedit-devel libxcrypt-devel -y


#简化依赖
yum install gcc make wget tar zlib-devel openssl-devel pam-devel libedit-devel krb5-devel -y

无公网

提前下载rpm/deb包
yumdownloader --resolve --destdir=./ gcc make wget tar zlib-devel openssl-devel pam-devel libedit-devel krb5-devel

1.3 编译安装openssl1.1.1w

下载
https://www.openssl.org/source/

本地文件:
openssl-1.1.1w.tar.gz
编译安装

tar -xf openssl-1.1.1w.tar.gz
cd openssl-1.1.1w
./config
make
make install

创建软连接

#CentOS
sudo ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/
sudo ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/


#Ubuntu
sudo ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1
sudo ln -s /usr/local/lib/libssl.so.1.1 /usr/lib/x86_64-linux-gnu/libssl.so.1.1

验证版本

openssl version -a

二、排错

2.1 make报错:

Unable to load host key "/etc/ssh/ssh_host_ed25519_key": bad permissions Unable to load host key: /etc/ssh/ssh_host_ed25519_key

处理方法:修改文件权限

chmod 600 /etc/ssh/ssh_host_*
chown root:root /etc/ssh/ssh_host_*

2.2 GSSAPI 相关警告

OpenSSH 10 默认编译没有开启 GSSAPI 支持,但是原配置文件保留了 GSSAPIAuthenticationGSSAPICleanupCredentials 选项,configure 没有 --with-gssapi 参数,所以报“Unsupported option”。

/etc/ssh/sshd_config line 79: Unsupported option GSSAPIAuthentication
/etc/ssh/sshd_config line 80: Unsupported option GSSAPICleanupCredentials

如果你不使用 Kerberos,可以直接注释掉 /etc/ssh/sshd_config 里这两行

#GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes

如果需要 Kerberos,确保系统安装了 krb5-devel
3.2 预编译 步骤中重新编译时填加(在下文中已添加,直接使用即可):

./configure ... --with-gssapi=/usr

2.3 root用户登录

老版本的openssh和新版本的openssh的默认值不同。
老版本默认允许root用户登录,新版本默认不允许。
如果在老版本的配置文件中

#PermitRootLogin yes

选项是被注释掉的,那么在老版本中root用户可以登录,升级到新版本后,就不能登录了。
因此需要把这里的注释去掉,显示声明允许root用户登录。

sed -i "s/#PermitRootLogin yes/PermitRootLogin yes/"  /etc/ssh/sshd_config

三、编译安装

3.1 下载源码

下载源码包
https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-10.0p1.tar.gz
本地文件
openssh-10.0p1.tar.gz
解压

tar -xf openssh-10.0p1.tar.gz

进入目录

cd openssh-10.0p1

3.2 预编译

3.2.1 替换安装方式(与下一步二选一)

LDFLAGS="-L/usr/local/lib64" CPPFLAGS="-I/usr/local/include" ./configure \
    --prefix=/usr \
    --sysconfdir=/etc/ssh \
    --with-pam \
    --with-ssl-dir=/usr/local \
    --with-md5-passwords \
    --with-gssapi=/usr

3.2.2 双版本安装方式(与上一步二选一)

LDFLAGS="-L/usr/local/lib64" CPPFLAGS="-I/usr/local/include" \
./configure \
  --prefix=/usr/local/openssh10 \
  --sysconfdir=/usr/local/openssh10/etc \
  --with-pam \
  --with-md5-passwords

参数解释:

参数解释
--prefix=/usr指定安装路径覆盖系统默认 /usr/bin/ssh*、/usr/sbin/sshd
--sysconfdir=/etc/ssh保持配置文件路径 /etc/ssh/sshd_config 不变
--with-pam启用 PAM 认证
--with-ssl-dir=/usr/local指定 OpenSSL 1.1.1w 的路径
--with-md5-passwords保持旧密码加密兼容(可选)
--with-gssapi=/usr开启 GSSAPI 支持(可选)

3.3 编译

分步执行,便于查看报错信息。

make

3.4 安装

make install

3.5 验证新版本

#替换安装
[root@localhost ~]# ssh -V
OpenSSH_10.0p2, OpenSSL 1.1.1w  11 Sep 2023

#双版本安装
[root@localhost ~]# /usr/local/openssh10/bin/ssh -V
OpenSSH_10.0p2, OpenSSL 1.1.1w  11 Sep 2023

四、其他配置

4.1 修改配置文件(双版本安装需要)

编辑配置文件

vim /usr/local/openssh10/etc/sshd_config

修改关键参数项

-  #Port 22
+  Port 2222
  
-  #PidFile /var/run/sshd.pid
+  PidFile /var/run/sshd-10.pid
  
-  #PermitRootLogin prohibit-password
+  PermitRootLogin yes

4.2 创建systemd(双版本安装需要)

创建配置文件

vim /etc/systemd/system/sshd10.service

添加配置

[Unit]
Description=OpenSSH 10.0 Daemon
After=network.target

[Service]
ExecStart=/usr/local/openssh10/sbin/sshd -D -f /usr/local/openssh10/etc/sshd_config
PIDFile=/var/run/sshd-10.pid
Restart=always

[Install]
WantedBy=multi-user.target

加载配置

systemctl daemon-reload

启动服务

systemctl enable --now sshd10

标签: none

添加新评论