openssh10.0p1 源码构建安装 & rpm安装包构建

文章目录

    • 源码包下载
    • [openssl 编译](#openssl 编译)
    • [openssh 编译](#openssh 编译)
      • [1. 安装基础软件](#1. 安装基础软件)
      • [2. 编译openssh](#2. 编译openssh)
      • [3. 重启sshd](#3. 重启sshd)
    • [openssh rpm构建](#openssh rpm构建)
      • [1. 安装rpmbuild](#1. 安装rpmbuild)
      • [2. 安装编译软件](#2. 安装编译软件)
      • [3. 目录构建](#3. 目录构建)
    • 异常处理
      • [` ldapdb_canonuser_plug_init() failed in sasl_canonuser_add_plugin() `](#ldapdb_canonuser_plug_init() failed in sasl_canonuser_add_plugin())

源码包下载

openssl 编译

编译

bash 复制代码
# 解压
tar -xf openssl-3.4.1.tar.gz
# 进去
cd openssl-3.4.1
#编译配置openssl安装目录
./config --prefix=/usr/local/openssl
#安装
make && make install

#复制openssl文件到/usr/bin/下
cp /usr/local/openssl/bin/openssl /usr/bin/
# 添加动态链接库数据
echo '/usr/local/openssl/lib64/' >> /etc/ld.so.conf
# 更新动态链接库
ldconfig
#创建软连接
ln -sf /usr/local/openssl/lib/libssl.so.3 /usr/lib/libssl.so.3
# 验证版本
openssl version

异常处理

bash 复制代码
# 报错处理:	
openssl: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory
# 解决方案
# 创建软连接
ln -sf /usr/local/openssl/lib/libssl.so.3 /usr/lib/libssl.so.3

openssh 编译

1. 安装基础软件

在编译openssh之前需要安装基础软件:

bash 复制代码
yum -y gcc tar make zlib-devel pam-devel cyrus-sasl-ldap
zlib源码编译

如果zlib-devel可以通过yum包管理器安装,则可以忽略此步骤。

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

2. 编译openssh

bash 复制代码
tar -zxvf openssh-10.0p1.tar.gz -C /opt/
cd openssh-10.0p1

# 源码编译zlib(二选一)
./configure \
  --prefix=/usr \
  --sysconfdir=/etc/ssh \
  --with-ssl-dir=/usr/local/openssl \
  --with-zlib==/usr/local/zlib \
  --with-pam
# yum安装zlib(二选一)
./configure \
  --prefix=/usr \
  --sysconfdir=/etc/ssh \
  --with-ssl-dir=/usr/local/openssl \
  --with-zlib \
  --with-pam

# 编译
make && make install

3. 重启sshd

  • 检查sshd的配置文件,是否适配新版本:

    bash 复制代码
    [root@localhost ~]# sshd -t
    /etc/ssh/sshd_config: line 157: Bad configuration option: GSSAPIKexAlgorithms
    /etc/ssh/sshd_config: terminating, 1 bad configuration options

    可以看到问题行号,直接注释掉问题行就可以。sshd -t没有报错了,继续下一步

  • 重启sshd

    bash 复制代码
    systemctl restart sshd 
  • 检查版本

    bash 复制代码
    [root@localhost ~]# ssh -V
    OpenSSH_10.0p2, OpenSSL 3.4.1 11 Feb 2025

openssh rpm构建

openrpm包构建后,rpm包可以分发到其他主机进行安装,而不用构建openssh编译环境。

1. 安装rpmbuild

bash 复制代码
yum install -y rpmdevtools rpmlint

2. 安装编译软件

bash 复制代码
yum install -y glibc-devel krb5-devel
yum install -y gtk2-devel libXt-devel openssl-devel imake

3. 目录构建

  • 生成构建目录

    bash 复制代码
    rpmdev-setuptree

    构建目录如下所示:

    bash 复制代码
    [root@localhost ~]# tree -L 2 /root/rpmbuild/
    /root/rpmbuild/
    ├── BUILD
    │   └── openssh-9.7p1
    ├── BUILDROOT
    ├── RPMS
    │   ├── aarch64
    │   └── x86_64
    ├── SOURCES
    │   ├── openssh-9.7p1.tar.gz
    │   └── x11-ssh-askpass-1.2.4.1.tar.gz
    ├── SPECS
    │   └── openssh.spec
    └── SRPMS
        └── openssh-9.7p1-1.oe1.bclinux.src.rpm
  • 拷贝spec文件和源码包

    bash 复制代码
    # spec文件位于openssh-10.0p2.tar.gz源码包, 解压到openssh-10.0p1
    cp -f openssh-10.0p1/contrib/redhat/openssh.spec  /root/rpmbuild/SPECS/
    cp -f openssh-10.0p2.tar.gz /root/rpmbuild/SOURCES/
    
    # x11-ssh-askpass
    cp -f x11-ssh-askpass-1.2.4.1.tar.gz /root/rpmbuild/SOURCES/

    x11-ssh-askpass下载:https://mirrors.aliyun.com/slackware/slackware64/source/xap/x11-ssh-askpass/

  • 修改spec文件

bash 复制代码
# spec文件在%files server 部分添加此行:
%attr(0755,root,root) %{_libexecdir}/openssh/sshd-auth
  • 开始构建
bash 复制代码
rpmbuild -bb /root/rpmbuild/SPECS/openssh.spec

之后就可以在 /root/rpmbuild/RPMS目录下发现当前架构的rpm包。

异常处理

ldapdb_canonuser_plug_init() failed in sasl_canonuser_add_plugin()

openssh编译完,运行需要的软件cyrus-sasl-ldap

bash 复制代码
# 安装 SASL LDAP 模块(可能包含在 cyrus-sasl-ldap 包中)
yum install cyrus-sasl-ldap

不装这个, openssh启动会报错ldapdb_canonuser_plug_init() failed in sasl_canonuser_add_plugin()

这个错误 ldapdb_canonuser_plug_init() failed in sasl_canonuser_add_plugin() 通常与 Cyrus SASL(Simple Authentication and Security Layer) 配置相关,特别是当 SASL 尝试加载 ldapdb 插件(用于通过 LDAP 数据库处理用户名规范化)时初始化失败。

安装办法:

  • Debian/Ubuntu 系统:
bash 复制代码
# 安装 SASL LDAP 模块
sudo apt install sasl2-modules-ldap
  • CentOS/RHEL 系统:
bash 复制代码
# 安装 SASL LDAP 模块(可能包含在 cyrus-sasl-ldap 包中)
sudo yum install cyrus-sasl-ldap
相关推荐
网络精创大傻1 天前
Terminator SSH 管理器 — 一款适用于 Terminator 的精美 SSH 连接插件
运维·ssh
HIT_Weston1 天前
23、【Ubuntu】【远程开发】内网穿透:SSH 反向隧道
linux·ubuntu·ssh
catoop2 天前
在 WSL 的 Ubuntu 中安装和配置 SSH 服务
linux·ubuntu·ssh
lxmyzzs2 天前
vscode-ssh无法进入docker问题解决
vscode·docker·ssh
程序员陆通4 天前
CentOS/AlmaLinux 9 中 SSH 服务启动失败:OpenSSL 版本不匹配解决
linux·centos·ssh
小马哥编程4 天前
JWT 是由哪三个部分组成?如何使用JWT进行身份认证?
网络协议·http·架构·ssh
小马哥编程5 天前
【软考架构】案例分析-web应用设计:SSH 和 SSM(Spring + Spring MVC + MyBatis ) 之间的区别,以及使用场景
前端·架构·ssh
半夏微凉半夏殇6 天前
VSCode Remote-SSH:无缝远程开发完全指南
ide·vscode·ssh
YuanDaima20486 天前
GitHub 与 Gitee 多平台 SSH Key 配置指南
gitee·开源·ssh·github·开源软件·key·免密登录
Fluency-116 天前
ubuntu中ssh连接root用户
linux·ubuntu·ssh