源码下载: OpenSSH: for OpenBSD
http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.8p1.tar.gz
tar xpf openssh-9.8p1.tar.gz
cd openssh-9.8p1
一、交叉编译器
export PATH=$PATH:/opt/toolchain/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf/bin
export ARCH=arm
export CROSS_COMPILE=/opt/toolchain/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
二、配置
依赖 openssl 和 zlib
这两个需要先交叉编译通过 openssl 和 zlib 编译
下载 zlib http://www.zlib.net/zlib-1.3.1.tar.gz
zlib 编译方法:
export CROSS_PREFIX=arm-linux-gnueabihf-
./configure --prefix=/workstation/zlib-1.3.1/build --shared
make
make install
./configure --host=arm --exec-prefix=/workstation/openssh-build --sysconfdir=/workstation/openssh-build/etc/ssh --disable-etc-default-login CC=arm-linux-gnueabihf-gcc --with-zlib=/workstation/openssh/zlib-1.3.1/build --with-ssl-dir=/workstation/openssl-build/ --disable-strip
三、编译
make
make install
四、遇到的报错
1、make: *** [host-key] Error 127
把Makefile 里面的 ./ssh-keygen 改为 ssh-keygen
2、make: [check-config] Error 127 (ignored)
Makefile 里面的 install: $(CONFIGFILES) $(MANPAGES) $(TARGETS) install-files install-sysconf host-key check-config 去掉 check-config
五、拷贝到目标机
把文件 /workstation/openssh-build 里分别拷贝到 /etc/ssh /usr/ 目录
还需要创建一个 /var/empty 的 root 用户文件。
拷贝完后运行 sshd -V 查看版本
# sshd -V
OpenSSH_9.8p1, OpenSSL 3.2.1 30 Jan 2024