在同一个局域网下,ubuntu linux
和开发板能 ping
通,但是 scp
传文件到开发板失败了,提示ssh remote_ip **** lose connection connection timeout
原因在于开发板上板子没有启动 sshd
这个服务 ,不然连不上的,然后发现板子上并没有sshd
因此需要交叉编译ssh服务到开发板上才能使用相关应用,这篇博客浅浅记录一下整个过程,一站式脚本用的也更得心应手了
以下均采用脚本进行编译,可自行根据脚本 download_package ()
中的下载地址下载包并存放在 compressed
目录中,如图
在一个空目录下新建一个脚本 ,如auto_compile.sh
,写入以下内容
#!/bin/sh
BASE=`pwd`
BUILD_HOST=arm-linux-gnueabihf
OUTPUT_PATH=${BASE}/arm_install
make_dirs () {
cd ${BASE} && mkdir compressed arm_install source -p
}
download_package () {
cd ${BASE}/compressed
wget https://www.zlib.net/fossils/zlib-1.2.12.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1q.tar.gz
wget http://ftp5.usa.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.0p1.tar.gz
}
tar_package () {
cd ${BASE}/compressed
ls * > /tmp/list.txt
for TAR in `cat /tmp/list.txt`
do
tar -xf $TAR -C ../source
done
rm -rf /tmp/list.txt
}
set_env () {
source /opt/pkg/petalinux/2018.3/settings.sh
}
make_zlib () {
cd ${BASE}/source/zlib*
./configure --prefix=${OUTPUT_PATH}/zlib
#Makefile 中的gcc和ar替换成自己的
sed -i '19,19s/gcc/arm-linux-gnueabihf-gcc/g' Makefile
sed -i '30,30s/gcc/arm-linux-gnueabihf-gcc/g' Makefile
sed -i '31,31s/gcc/arm-linux-gnueabihf-gcc/g' Makefile
sed -i '39,39s/ar/arm-linux-gnueabihf-ar/g' Makefile
make -j8 && make install
}
make_openssl () {
cd ${BASE}/source/openssl*
./config shared no-asm \
--prefix=${OUTPUT_PATH}/openssl \
--openssldir=${BASE}/source/openssl-1.1.1q/ssl
#CROSS_COMPILE= 添加 arm-linux-gnueabihf-
sed -i '92,92s/CROSS_COMPILE=/CROSS_COMPILE=arm-linux-gnueabihf-/g' Makefile
#去掉 -m64 标签,否则会报错
sed -i '126,126s/-m64//g' Makefile
sed -i '127,127s/-m64//g' Makefile
sed -i '129,129s/-m64//g' Makefile
make -j8 && make install
}
make_openssh () {
cd ${BASE}/source/openssh*
./configure --host=arm-linux \
--with-zlib=${OUTPUT_PATH}/zlib \
--with-ssl-dir=${OUTPUT_PATH}/openssl \
--disable-etc-default-login --disable-strip \
CC=${BUILD_HOST}-gcc \
AR=${BUILD_HOST}-ar
make -j8
}
make_dirs
set_env
tar_package
make_zlib
make_openssl
make_openssh
查看开发板上有没有以下目录,若没有,则新建:
/usr/local/bin/
/usr/local/sbin/
/usr/local/etc/
/usr/local/libexec/
/var/run/
/var/empty/
cd **/source/openssh-9.0p1
sudo cp scp sftp ssh ssh-add ssh-agent ssh-keygen ssh-keyscan /media/hammer/rootfs/usr/local/bin
sudo cp moduli ssh_config sshd_config /media/hammer/rootfs/usr/local/etc
sudo cp sftp-server ssh-keysign /media/hammer/rootfs/usr/local/libexec
sudo cp sshd /media/hammer/rootfs/usr/local/sbin/
sync
cd **/source/openssh-9.0p1
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 ""
sudo cp ssh_host_*_key /media/hammer/rootfs/usr/local/etc/
sudo vi /etc/passwd
#在最后添加一行
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
ssh root@remote_ip
scp file root@remote_folder