itop4412 openssh-8.0p1移植教程

前言

在上一篇文章 itop4412 linux驱动学习环境搭建-最小根文件系统制作与NFS挂载 中,搭建了学习驱动的环境,本文续接上篇文章,进行openssh的移植,使得以后可以远程通过ssh连接开发板,也能通过sftp上传下载文件。

编译环境

前言中的上一篇文章相同,采用ubuntu18.04 LTS + gcc-arm-linux-gnueabihf(默认7.4.0)。

源码下载

openssh依赖于zlib和openssl库,本文采用目前最新stable分支进行移植,下载如下三个源码文件:

构建

对于zlib库和openssl库都可以指定install目录,这里在构建前先创建好该目录。笔者这里目录为: /home/jason/arm-devlop/ssh/install,在ssh目录下为源码所在目录,效果如下:

jason@jason-vm:~/arm-devlop/ssh$ ls
install               openssh-8.0p1         openssl-1.1.1c.tar.gz
openssh-7.8p1.tar.gz  openssh-8.0p1.tar.gz  zlib-1.2.11
openssh-7.9p1.tar.gz  openssl-1.1.1c        zlib-1.2.11.tar.gz
jason@jason-vm:~/arm-devlop/ssh$ 

移植zlib

  1. 执行编译脚本build.sh
    这里直接贴出笔者总结的配置脚本,如下:
jason@jason-vm:~/arm-devlop/ssh/zlib-1.2.11$ cat build.sh 
#########################################################################
# File Name: build.sh
# Author: jason416
# mail: jason416@foxmail.com
# Created Time: 2019年07月14日 星期日 14时32分37秒
# License: GPL v2
#########################################################################
#!/bin/bash

export CC=arm-linux-gnueabihf-gcc
export AR=arm-linux-gnueabihf-ar
export LD=arm-linux-gnueabihf-ld
export ANLIB=arm-linux-gnueabihf-ranlib
INSTALL=/home/jason/arm-devlop/ssh/install/zlib-1.2.11

./configure --prefix=$INSTALL

echo "------------------------"
echo "end of configure"
echo "------------------------"

if [ -e Makefile ]; then
	make && make install
fi

jason@jason-vm:~/arm-devlop/ssh/zlib-1.2.11$ 
  1. 构建后文件目录
    在完成install操作后,会将生成的目标文件按Makefile里的相应规则,拷贝到install目录下,目录如下:
jason@jason-vm:~/arm-devlop/ssh/install/zlib-1.2.11$ tree
.
├── include
│   ├── zconf.h
│   └── zlib.h
├── lib
│   ├── libz.a
│   ├── libz.so -> libz.so.1.2.11
│   ├── libz.so.1 -> libz.so.1.2.11
│   ├── libz.so.1.2.11
│   └── pkgconfig
│       └── zlib.pc
└── share
    └── man
        └── man3
            └── zlib.3

6 directories, 8 files
jason@jason-vm:~/arm-devlop/ssh/install/zlib-1.2.11$ 

移植openssl

  1. 执行编译脚本build.sh

这里直接贴出笔者总结的配置脚本,如下:

jason@jason-vm:~/arm-devlop/ssh/openssl-1.1.1c$ cat build.sh 
#########################################################################
# File Name: build.sh
# Author: jason416
# mail: jason416@foxmail.com
# Created Time: 2019年07月14日 星期日 14时32分37秒
# License: GPL v2
#########################################################################
#!/bin/bash
INSTALL=/home/jason/arm-devlop/ssh/install

./Configure --prefix=$INSTALL/openssl-1.1.1c linux-armv4 --cross-compile-prefix=arm-linux-gnueabihf- --release --with-zlib-include=/home/jason/arm-devlop/ssh/install/zlib-1.2.11/include --with-zlib-lib=/home/jason/arm-devlop/ssh/install/zlib-1.2.11/lib zlib-dynamic zlib

echo "------------------------"
echo "end of configure"
echo "------------------------"

if [ -e Makefile ]; then
	make && make install
fi

jason@jason-vm:~/arm-devlop/ssh/openssl-1.1.1c$ 

  1. 构建后文件目录

在完成install操作后,会将生成的目标文件按Makefile里的相应规则,拷贝到install目录下,目录如下:

jason@jason-vm:~/arm-devlop/ssh/install/openssl-1.1.1c$ tree -L 2 
.
├── bin
│   ├── c_rehash
│   └── openssl
├── include
│   └── openssl
├── lib
│   ├── engines-1.1
│   ├── libcrypto.a
│   ├── libcrypto.so -> libcrypto.so.1.1
│   ├── libcrypto.so.1.1
│   ├── libssl.a
│   ├── libssl.so -> libssl.so.1.1
│   ├── libssl.so.1.1
│   └── pkgconfig
├── share
│   ├── doc
│   └── man
└── ssl
    ├── certs
    ├── ct_log_list.cnf
    ├── ct_log_list.cnf.dist
    ├── misc
    ├── openssl.cnf
    ├── openssl.cnf.dist
    └── private

13 directories, 12 files
jason@jason-vm:~/arm-devlop/ssh/install/openssl-1.1.1c$ 

openssh移植

构建

  1. 执行编译脚本build.sh
    这里直接贴出笔者总结的配置脚本,如下:
jason@jason-vm:~/arm-devlop/ssh/openssh-8.0p1$ cat build.sh 
#########################################################################
# File Name: build.sh
# Author: jason416
# mail: jason416@foxmail.com
# Created Time: 2019年07月14日 星期日 14时32分37秒
# License: GPL v2
#########################################################################
#!/bin/bash

export CC=arm-linux-gnueabihf-gcc
export AR=arm-linux-gnueabihf-ar
export LD=arm-linux-gnueabihf-ld
export ANLIB=arm-linux-gnueabihf-ranlib

./configure --host=arm-linux-gnueabihf --with-libs --with-zlib=$INSTALL/zlib-1.2.11 --with-ssl-dir=$INSTALL/openssl-1.1.1c --disable-etc-default-login --with-md5-passwords HOST_OS=linux --with-ssl-engine --with-openssl LIBS="-lpthread" 

echo "------------------------"
echo "end of configure"
echo "------------------------"

if [ -e Makefile ]; then
	make
fi

jason@jason-vm:~/arm-devlop/ssh/openssh-8.0p1$ 

  1. 说明

针对openssh构建后,不需要执行make install操作,因为其生成的文件需要手动按照configure后的打印信息(如下)所指定目录放置。在成功构建后会打印一下信息:

OpenSSH has been configured with the following options:
                     User binaries: /usr/local/bin
                   System binaries: /usr/local/sbin
               Configuration files: /usr/local/etc
                   Askpass program: /usr/local/libexec/ssh-askpass
                      Manual pages: /usr/local/share/man/manX
                          PID file: /var/run
  Privilege separation chroot path: /var/empty
            sshd default user PATH: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
...

配置

  • 拷贝构建的openssh相关文件
jason@jason-vm:~/arm-devlop/ssh/openssh-8.0p1$ mkdir -p ~/rootfs/usr/libexec ~/rootfs/usr/local/etc ~/rootfs/usr/local/bin ~/rootfs/usr/local/sbin
jason@jason-vm:~/arm-devlop/ssh/openssh-8.0p1$ cp scp  sftp  ssh sshd  ssh-add  ssh-agent  ssh-keygen  ssh-keyscan ~/rootfs/usr/local/bin/
jason@jason-vm:~/arm-devlop/ssh/openssh-8.0p1$ cp sshd ~/rootfs/usr/local/sbin/
jason@jason-vm:~/arm-devlop/ssh/openssh-8.0p1$ cp moduli ssh_config sshd_config ~/rootfs/usr/local/etc/
jason@jason-vm:~/arm-devlop/ssh/openssh-8.0p1$ cp sftp-server ssh-keysign ~/rootfs/usr/libexec/
  • 拷贝前面构建的zlib和openssl库
jason@jason-vm:~/arm-devlop/ssh/openssh-8.0p1$ cp ../install/zlib-1.2.11/lib/libz.so* ~/rootfs/lib/ -a
jason@jason-vm:~/arm-devlop/ssh/openssh-8.0p1$ cp ../install/openssl-1.1.1c/lib/libcrypto.so* ~/rootfs/lib -a
jason@jason-vm:~/arm-devlop/ssh/openssh-8.0p1$ cp ../install/openssl-1.1.1c/lib/libssl.so* ~/rootfs/lib -a

注:~/rootfs为开发板挂载的最小根文件系统的/(根目录),-a参数必须指定,否则软链接在拷贝后会失效。

  • 生成开发板sshd运行所需私钥文件
    在串口终端中输入以下命令,生成秘钥和公钥文件,并设置私钥文件权限为0600(八进制,rw-------)。
[root@iTOP-4412]# mkdir -p /etc/ssh && cd /etc/ssh/
[root@iTOP-4412]# ssh-keygen -t rsa -f ssh_host_rsa_key -N ""
[root@iTOP-4412]# ssh-keygen -t dsa -f ssh_host_dsa_key -N ""
[root@iTOP-4412]# ssh-keygen -t ecdsa -f ssh_host_ecdsa_key -N ""
[root@iTOP-4412]# ssh-keygen -t ed25519 -f ssh_host_ed25519_key -N ""
[root@iTOP-4412]# ls /etc/ssh/                                                                                                          
ssh_host_dsa_key          ssh_host_ecdsa_key.pub    ssh_host_rsa_key
ssh_host_dsa_key.pub      ssh_host_ed25519_key      ssh_host_rsa_key.pub
ssh_host_ecdsa_key        ssh_host_ed25519_key.pub
[root@iTOP-4412]# chmod 0600 ssh_host_ed25519_key ssh_host_rsa_key ssh_host_rsa_key ssh_host_dsa_key
  • 其他文件修改
  1. 修改用户组文件**/etc/passwd**,添加如下内容:
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
  1. 修改sshd配置文件
    修改sshd_config文件为如下所示,其他内容可根据自己需要进行修改。
...

HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

...
#PermitRootLogin prohibit-password
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

...
  • 为root用户添加/修改密码

ssh连接方式有两种,一种是常规的用户名+密码形式,另一种是用ssh-keygen生成的.pub公钥,这里只介绍常规方式。

[root@iTOP-4412]# passwd                                                                                                                           
Changing password for root
New password: 
Bad password: too short
Retype password: 
passwd: password for root changed by root
[root@iTOP-4412]# 
  • 设置sshd为自启动

在/etc/init.d/rcS中最后一行添加如下命令:

/usr/local/sbin/sshd

效果

在成功完成上述配置后,便可以用开发机连接开发板,也可用开发板连接开发机,如下图所示:
相互连接测试

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OpenSSH 8.0 发布了,此版本缓解了 scp(1) 工具和协议漏洞 CVE-2019-6111,该漏洞此前我们之前报导过:知名文件传输协议 SCP 被曝存在 35 年历史的安全漏洞。 将文件从远程系统复制到本地目录时,SCP 客户端无法验证 SCP 服务器返回的对象是否与请求的东西一致,这使得攻击者可以使用恶意服务器控制的内容创建或破坏本地文件。 OpenSSH 8.0 的缓解措施添加了客户端检查,查看从服务器发送的文件名与命令行请求是否匹配。 SCP 协议已经过时,不灵活且不易修复,OpenSSH 官方建议使用更现代的协议进行文件传输,如 sftp 和 rsync。 此版本新特性包括: ssh(1)、ssh-agent(1)、ssh-add(1):PKCS#11 token 中添加对 ECDSA 密钥的支持。 ssh(1)、sshd(8):基于 Streamlined NTRU Prime 4591^761 和 X25519 的组合,添加实验性量子计算抗性密钥交换方法。 ssh-keygen(1):将默认 RSA 密钥大小增加到 3072 位。 ssh(1):允许“PKCS11Provider = none”覆盖 ssh_config 中 PKCS11Provider 指令的后续实例。 ssh(1):提示是否录制新主机密钥时,输入密钥指纹作为“yes”。 ssh-keygen(1):在单个命令行调用上签名多个证书时,允许自动递增证书序列号。 scp(1)、sftp(1):接受 -J 选项作为 scp 和 sftp 命令行上 ProxyJump 的别名。 ssh-agent(1)、ssh-pkcs11-helper(8)、ssh-add(1):接受“-v”命令行标志以增加输出的详细程度;将详细标志传递给子进程,例如从 ssh-agent 启动的 ssh-pkcs11-helper。 ssh-add(1):添加“-T”选项以允许通过执行签名和验证来测试代理中的密钥是否可用。 sshd(8):在 PAM 环境中暴露 $SSH_CONNECTION。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值