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
相关推荐
悟空空心20 小时前
服务器长ping,traceroute
linux·服务器·网络·ssh·ip·ping++
zfj32121 小时前
sshd除了远程shell外还有哪些功能
linux·ssh·sftp·shell
张童瑶1 天前
Linux SSH配置密钥文件及免密登录
linux·运维·ssh
加成BUFF1 天前
树莓派安装下载及远程连接(共用手机热点)(SSH)(VNC)
linux·计算机·ssh·bash·树莓派·vnc
一往无前fgs1 天前
【国产信创】openEuler 22.03 安全加固:SSH 端口修改完整指南(含防火墙/SELinux 配置)
网络·安全·ssh·openeuler
Swift社区1 天前
LeetCode 451 - 根据字符出现频率排序
算法·leetcode·ssh
Bruce_Liuxiaowei2 天前
SSH主机密钥验证失败(Host key verification failed)深度解析与解决方案
运维·网络·ssh
CCI3442 天前
Remote ssh无法连接?
运维·ssh
张童瑶3 天前
Linux SSH隧道代理转发及多层转发
linux·运维·ssh
m0_738120723 天前
应急响应——知攻善防蓝队靶机Web-1溯源过程
前端·网络·python·安全·web安全·ssh