openssh 9.6交叉编译ls1043

准备工作

zlib:
官网下载:https://www.zlib.net
版本:zlib-1.2.2.tar.gz
openssl:
官网下载:https://www.openssl.org/source
版本:openssl-1.1.1k.tar.gz
openssh:
官网下载:http://www.openssh.com/portable.html
阿里云镜像:https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable
版本:openssh-8.5p1.tar.gz
pam:
https://github.com/linux-pam/linux-pam/releases
我使用的是1.6.0版本

交叉编译zib 私有编译链

测试一:

错误示范:
当编译链不是通用编译连的时候configure 参数里面是没有CC和host参数内容为aarch64-fsl-linux-gnu-gcc

./configure --prefix=/home/fangkai/openssh_bypass1043/zlib-1.3.1/build CC=aarch64-fsl-linux-gnu-gcc CFLAGS="-static -fPIC"

报错:
image

测试二
错误示范

./configure --prefix=/home/fangkai/openssh_bypass1043/zlib-1.3.1/build --host=aarch64-fsl-linux-gnu

image

正确配置
configrure前面预先配置编译器CC为你要的编译环境

CC=aarch64-fsl-linux-gnu-gcc CFLAGS="-static -fPIC" ./configure --prefix=/home/fangkai/openssh_bypass1043/zlib-1.3.1/build

放在前面就可以配置通过,cflag
CFLAGS 中的 -static 参数指示编译器生成静态链接的可执行文件,而 -fPIC 参数用于生成位置无关代码,这对于生成共享库(.so 文件)是必要的。因此,CFLAGS="-static -fPIC" 表示您希望生成静态链接的可执行文件,并且在编译过程中使用位置无关代码。
发现加cflags会报错,所以去掉了
因此,CFLAGS="-static -fPIC" 的效果是生成静态连接的可执行文件,并且在编译共享库时使用位置无关代码。
image

编译openssl

./Configure  linux-aarch64 --cross-compile-prefix=aarch64-fsl-linux-gnu-  --prefix=/home/fangkai/openssh_bypass1043/openssl-1.1.1w/build shared no-asm no-async

image

编译pam

需要依赖cracklib (测试发现1.6.0版本不需要这个也可以编译通过)

下载地址 https://github.com/cracklib/cracklib/releases/download/v2.9.7/cracklib-2.9.7.tar.bz2

# 解压
tar xjf cracklib-2.9.7.tar.bz2
# 配置交叉编译,因为我用的不是标准的aarch64编译链,所以需要加CC 和AR参数
./configure --host=aarch64-linux-gnu --prefix=/home/fangkai/openssh_bypass1043/cracklib-2.9.7/build CC=aarch64-fsl-linux-gnu-gcc AR=aarch64-fsl-linux-gnu-ar
make && make install

编译linux-pam 1.6

wget https://github.com/linux-pam/linux-pam/archive/refs/tags/v1.3.1.tar.gz --no-check-certificate

./configure --host=aarch64-fsl-linux-gnu --prefix=/home/fangkai/openssh_bypass1043/linux-pam-1.6.0/build  --disable-doc CC=aarch64-fsl-linux-gnu-gcc

编译报错max-size,尝试修改

vim /home/fangkai/openssh_bypass1043/linux-pam-1.6.0/modules/pam_namespace/pam_namespace.c

image

编译openssh

./configure --host=aarch64-fsl-linux-gnu --prefix=/home/fangkai/openssh_bypass1043/openssh-9.6p1/build --with-zlib=/home/fangkai/openssh_bypass1043/zlib-1.3.1/build/ --with-ssl-dir=/home/fangkai/openssh_bypass1043/openssl-1.1.1w/build --sysconfdir=/etc/ssh
make

更新

补充:
交叉编译加入pam模块

LDFLAGS=-L/root/pam/linux-pam-1.6.0/build/lib LIBS=-lpam ./configure --host=aarch64-linux-gnu --prefix=/home/fangkai/sshlatest/build_arm --with-zlib=/root/zlib/zlib-1.3/build_arm --with-ssl-dir=/home/fangkai/openssh_bypass1043/openssl-3.2.1/build --with-pam --sysconfdir=/etc/ssh
posted @ 2024-01-30 16:17  学不会xuebuhui  阅读(102)  评论(0编辑  收藏  举报
Language: javascript