红字加粗为编译器不同、路径不同需要注意修改的地方
一、源码包下载:
- zlib官方下载:zlib Home Site
- openssl官方下载:http://www.openssl.org/source
- openssh官网下载:OpenSSH: Portable Release
本文使用版本:
zlib-1.2.12
openssl-3.0.4
openssh-9.0p1
二、编译安装zlib
tar xvzf zlib-1.2.12.tar.gz cd zlib-1.2.12 mkdir install ./configure --prefix=/work/plug-in/sshd-imx6/zlib-1.2.12/install/ vi Makefile #将Makefile文件中的gcc都手动修改为arm-linux-gcc :%s/gcc/arm-linux-gcc/g make -j32 make install
三、编译安装openssl
tar xvzf openssl-3.0.4.tar.gz cd openssl-3.0.4 mkdir install ./config no-asm shared linux-generic32 --prefix=/work/plug-in/sshd-imx6/openssl-3.0.4/install/ --cross-compile-prefix=arm-linux- make -j32 make install
注:一定要加上linux-generic32对应的架构
四、编译openssh
tar xvzf openssh-9.0p1.tar.gz cd openssh-9.0p1 ./configure --host=arm-linux --with-libs --with-zlib=/work/plug-in/sshd-imx6/zlib-1.2.12/install/ --with-ssl-dir=/work/plug-in/sshd-imx6/openssl-3.0.4/install/ --disable-etc-default-login CC=arm-linux-gcc AR=arm-linux-ar make -j32 make install
将生成软件放到目标板对应目录
cp scp sftp ssh ssh-add ssh-agent ssh-keygen ssh-keyscan /opt/filesystem/imx6/rootfs/usr/local/bin/
cp moduli ssh_config sshd_config /opt/filesystem/imx6/rootfs/usr/local/
cp moduli ssh_config sshd_config /opt/filesystem/imx6/rootfs/usr/local/etc/
cp sftp-server ssh-keysign /opt/filesystem/imx6/rootfs/usr/libexec/
cp sshd /opt/filesystem/imx6/rootfs/usr/sbin/
chmod 777 /opt/filesystem/imx6/rootfs/usr/local/bin/*
chmod 777 /opt/filesystem/imx6/rootfs/usr/sbin/*
五、生成密钥文件
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 dsa -f ssh_host_ed25519_key -N ""
chmod 600 ssh_host_ed25519_key
cp ssh_host_* /opt/filesystem/imx6/rootfs/usr/local/etc/
六、修改ssh配置文件
1. /usr/local/sshd_config和/usr/local/etc/sshd_config,将PermitRootLogin yes前的注释“#”号去掉。
2. /etc/passwd 文件,在最后添加下面这一行:
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
3.如果开发板的 root 用户还没有密码,键入以下命令然输入两次密码来修改,否其他设备无法连:
passwd root
4.将sshd加入开机启动项
修改/etc/init.d/rcS增加/usr/sbin/sshd
七、软件远程登录