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
相关推荐
与自己和解74116 小时前
使用ssh实现 VScode 直连 ubuntu
vscode·ubuntu·ssh
lingran__2 天前
Git 完全指南(三):远程仓库与标签管理
开发语言·git·gitee·ssh·团队协作·远程仓库·分布式版本控制
Tassel_YUE2 天前
非 ansible 主机批量执行命令方法:psssh 和 pscp(随手记)
linux·网络·ssh·scp·ansible
JZZC23 天前
1.1 基础的SSH配置
计算机网络·ssh
深念Y4 天前
Windows 11 工具链部署与 SSH 踩坑笔记
windows·笔记·ssh
mooooooooooye5 天前
2026 年跨平台 SSH 客户端怎么选?Xterminal、Termius、MobaXterm 谁更合适
服务器·网络·ssh
小王C语言6 天前
Windows 无法使用 ssh 连接虚拟机(ubuntu),网络没问题的情况下
运维·ssh
mooooooooooye7 天前
SSH 工具越用越乱,Xterminal 先清掉这三类失效连接
运维·ssh·github
梓沂7 天前
SSH 公钥认证配置指南:从生成密钥到配置 SFTP 服务器
ssh
lswzw8 天前
我开源了 ssh-mcp:让支持 MCP 的 AI 客户端通过 SSH 查服务器、查数据库、读文件和部署
人工智能·开源·ssh