[xhr4412][extension 5] 使用 SSH 登录 xhr4412

   使用串口有些时候还是感觉不方便,还是觉得能连接的线越少越好,既然网口不能省,那就只有使用 SSH 来登录 xhr4412 了。

主要需要三个东西:

  1. zlib
  2. openssl
  3. openssh

一、编译

1. zlib

官网:http://www.zlib.net/
下载:http://www.zlib.net/fossils/

   当前最新为 zlib 1.2.11 January 15, 2017,看来是三年前的了,应该非常稳定了。

build:

  1. ./configure --prefix=$PWD/out
  2. vim Makefile
  3. make
  4. make install

Makefile 中将红线处换为自己的编译器。

在这里插入图片描述
copy to compiler:

export XHR_CC_LIB_PATH=/home/xhr/iTop4412/crossCompiler/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc/lib
export XHR_CC_INCLUDE_PATH=/home/xhr/iTop4412/crossCompiler/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc/usr/include
  1. cd out
  2. cp -p include/* $XHR_CC_INCLUDE_PATH/
  3. cp -dp lib/*so* $XHR_CC_LIB_PATH/

2. openssl

官网:https://www.openssl.org/

22-Sep-2020 OpenSSL 1.1.1h is now available, including bug fixes

   看来最新的版本 OpenSSL 1.1.1h 就在三天前刚发布,真是非常新了。

build:

   真是让人感动,opendssl 有 INSTALL 文档详细讲了如何配置编译安装,不像上面 zlib,我好像没找到安装文档。

  1. ./Configure --prefix=$PWD/out/install --openssldir=$PWD/out/config --cross-compile-prefix=arm-none-linux-gnueabihf- linux-armv4 zlib-dynamic
  2. make && make install

copy to compiler:

  1. cd out/install/
  2. cp -rp include/openssl/ $XHR_CC_INCLUDE_PATH/
  3. cp -dp lib/*so* $XHR_CC_LIB_PATH/

3. openssh

官网:http://www.openssh.com/
下载:http://www.openssh.com/portable.html#ftp
   https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/

   OpenSSH 8.3 released May 27, 2020 最新版本也是还没发布多久。

build:

  1. ./configure --host=arm-none-linux-gnueabihf
  2. make

   此处只需要编译,不需要安装。而且不能指定安装路径,openssh 会把指定的路径硬编码到程序中,很不方便,所以还是使用默认方式,但是一定不要安装,否则覆盖了本机 ssh 就麻烦了。

二、根文件系统

1. 复制 ssh 需要的文件

   前面已经编译好了三个必要的工程,现在需要把编译出来的必要文件复制到之前制作的根文件系统中,主要是动态库、应用程序、配置文件等。

1.1 动态库

   动态库比较简单,可以参照前面将 *so* 拷贝到编译器,同样将那些 *so* 拷贝到根文件系统的 /lib 目录即可。

1.2 openssh

   拷贝 openssh 的应用程序和配置文件,为什么要拷贝到这些路径,这个需要看文档。首先 cd 到编译好的 openssh 目录,执行下面命令:

mkdir -p usr/local/bin  # OpenSSH binaries
mkdir -p usr/local/etc  # configuration files
mkdir -p usr/local/sbin # the server
mkdir -p usr/local/libexec
mv scp sftp ssh ssh-add ssh-agent ssh-keygen ssh-keyscan usr/local/bin
cp -p sshd_config ssh_config usr/local/etc
mv sshd usr/local/sbin
mv sftp-server ssh-keysign usr/local/libexec
cp -rp usr ${rootfs} # rootfs path

2. 文件配置

   为了方便,修改 /etc/profile 中的环境变量路径,添加 /usr/local/bin:/usr/local/sbin:/usr/local/libexec

2.1 /etc/passwd

   需要添加一个 sshd 的用户,root 用户需要使用 passwd 命令设置密码。xhr4412 默认密码为 xhr。

root:4T10oEI5Tce1Q:0:0:root:/:/bin/sh
sshd::126:65534::/var/empty:/usr/sbin/nologin

2.2 /usr/local/etc

生成密钥对:

  1. ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
  2. ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key

   其实生成一个就行了,但是要把私钥文件设置权限为 400

2.3 /usr/local/etc/sshd_config

   该文件为 SSH 服务器的配置文件,可能需要打开这几个配置:

HostKey /etc/ssh/ssh_host_rsa_key
PermitRootLogin yes
Subsystem       sftp    /usr/libexec/sftp-server

2.4 other

mkdir var/empty
chmod 700 var/empty

3. 启动服务

  • /usr/local/sbin/sshd

   必须使用绝对路径,如果没有报错就说明服务已经启动,可以尝试能否登录成功了。

三、免密登录

   TODO

参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值