sshd的交叉编译

886 阅读1分钟

一.下载以下文件用于交叉编译

> zlib-1.2.8.tar.gz
> openssl-1.0.1h.tar.gz
> openssh-7.9p1.tar.gz

因使用的gblic的版本比较高,下载的openssh的版本也要高一点,否则编译链接时报错:找不到符号setuid@.\color{red}{因使用的gblic的版本比较高,下载的openssh的版本也要高一点,否则编译链接时报错:找不到符号`setuid@`.}

二.交叉编译zlib-1.2.8

1. ./configure --prefix=/home/bixiao/arm-linux-gnueabihf/zlib-1.2.8
2. 修改Makefile: 
	CC=arm-linux-gnueabihf-gcc
	AR=arm-linux-gnueabihf-ar rc
	CPP=arm-linux-gnueabihf-gcc -E
	LDSHARED=arm-linux-gnueabihf-gcc
3. make -j4 
4. make install

三.交叉编译openssl-1.0.1h.tar.gz

1. ./Configure --prefix=/usr/local/ssl  os/compiler:arm-linux-gnueabihf  	

安装的目录一定要是/usr/local/ssl,编译opensshwithssldir选项不起作用.\color{red}{安装的目录一定要是/usr/local/ssl, 编译openssh的--with-ssl-dir选项不起作用.} 否则编译openssh:configure:error:penSSLheadersmissingpleaseinstallfirstorcheckconfig.log\color{red}{否则编译openssh报:configure: error: penSSL headers missing - please install first or check config.log}

2. 修改Makefile:
	OpenSSL的Makefile中的CFLAG项中加入-fPIC        

否则编译openssh:configure:error:CantfindrecentOpenSSLlibcrypto(seeconfig.logfordetails)\color{red}{否则编译openssh报:configure: error: Can't find recent OpenSSL libcrypto (see config.log for details) }

3. make -j4 
4. make install

四. 交叉编译openssh-7.9p1.tar.gz

1. ./configure --host=arm-linux-gnueabihf --with-libs --with-zlib=/home/bixiao/arm-linux-gnueabihf/zlib-1.2.8-install/ --with-ssl-dir=/usr/local/ssl/ --disable-etc-default-login CC=arm-linux-gnueabihf-gcc AR=arm-linux-gnueabihf-ar
2. make(不需要make install)

五. 目标文件放入板子中运行

1. copy文件

2. ssh_host_*_key生成:
	ssh-keygen -t rsa -f ssh_host_rsa_key -N ""
	ssh-keygen -t dsa -f ssh_host_dsa_key -N ""
	ssh-keygen -t ecdsa -f ssh_host_ecdsa_key -N ""
    ssh-keygen -t rsa1 -f ssh_host_key -N ""
    
3. 修改/usr/local/etc/sshd_config

4. 测试,运行/usr/local/sbin/sshd

若运行,没有反应,查看/var/cache/messages,出现fatal:daemon()failed:Nosuchdevice\color{red}{若运行,没有反应,查看/var/cache/messages,出现fatal: daemon() failed: No such device}