移植 ssh

1. 简介

    ssh是远程登陆的一种,在服务器端开启sshd,远程就可以通过ssh协议登陆服务器。同ssh一起的自带sftp子线程,可以实现文件的传送。ssh 同 telnet 相比,是一种加密传输,相对安全。

 

2. 移植

2.1 编译zlib

./configure --prefix=/home/ohehe/wor_lip/porting/ssh/install/zlib CC="arm-fsl-linux-gnueabi-gcc -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/ohehe/ls1021-toolchain/sysroots/cortexa7hf-vfp-neon-fsl-linux-gnueabi" AR="arm-fsl-linux-gnueabi-ar -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/ohehe/ls1021-toolchain/sysroots/cortexa7hf-vfp-neon-fsl-linux-gnueabi"

更改Makefile中的 CC

arm-fsl-linux-gnueabi-gcc -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/ohehe/ls1021-toolchain/sysroots/cortexa7hf-vfp-neon-fsl-linux-gnueabi

AR为arm-fsl-linux-gnueabi-ar

所有gcc更改成$(CC)

make

make install

 

2.2 编译openssl

./Configure --prefix=/home/ohehe/wor_lip/porting/ssh/install/openssl os/compiler:arm-fsl-linux-gnueabi-gcc

更改Makefile中CC

变成

CC= arm-fsl-linux-gnueabi-gcc -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/ohehe/ls1021-toolchain/sysroots/cortexa7hf-vfp-neon-fsl-linux-gnueabi

 

2.3 编译ssh

./configure --host=arm-linux --prefix=/home/ohehe/wor_lip/porting/ssh/install/openssh --with-libs --with-zlib=/home/ohehe/wor_lip/porting/ssh/install/zlib --with-ssl-dir=/home/ohehe/wor_lip/porting/ssh/install/openssl --disable-etc-default-login CC=" arm-fsl-linux-gnueabi-gcc -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/ohehe/ls1021-toolchain/sysroots/cortexa7hf-vfp-neon-fsl-linux-gnueabi" AR=arm-fsl-linux-gnueabi-ar

make

手动将编译出来的文件拷贝到安装路径下

mkdir -p /home/ohehe/wor_lip/porting/ssh/install/openssh/usr/local/bin/
mkdir -p /home/ohehe/wor_lip/porting/ssh/install/openssh/usr/local/
mkdir -p /home/ohehe/wor_lip/porting/ssh/install/openssh/usr/local/etc/
mkdir -p /home/ohehe/wor_lip/porting/ssh/install/openssh/usr/libexec/
mkdir -p /home/ohehe/wor_lip/porting/ssh/install/openssh/usr/sbin/

mkdir -p /home/ohehe/wor_lip/porting/ssh/install/openssh/bin
cp scp sftp ssh ssh-add ssh-agent ssh-keygen ssh-keyscan moduli ssh_config sshd_config sftp-server ssh-keysign sshd /home/ohehe/wor_lip/porting/ssh/install/openssh/bin -a


cp scp sftp ssh ssh-add ssh-agent ssh-keygen ssh-keyscan /home/ohehe/wor_lip/porting/ssh/install/openssh
cp moduli ssh_config sshd_config  /home/ohehe/wor_lip/porting/ssh/install/openssh/usr/local/
cp moduli ssh_config sshd_config /home/ohehe/wor_lip/porting/ssh/install/openssh/usr/local/etc/
cp sftp-server ssh-keysign 

要有 /var/empty 文件

在文件夹 /etc/ssh 下生成 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 dsa -f ssh_host_ed25519_key -N ""

将生成的key文件放到文件夹/etc/ssh下

更改配置文件内容 sshd_config

打开

HostKey /etc/ssh/ssh_host_rsa_key

HostKey /etc/ssh/ssh_host_dsa_key

HostKey /etc/ssh/ssh_host_ecdsa_key

HostKey /etc/ssh/ssh_host_ed25519_key

更改,允许root用户登录

PermitRootLogin yes

允许无密码登录

PermitEmptyPasswords yes

另外

sshd放入

新建文件夹 /usr/local/openssh/bin

将相关可执行文件放入上边那个文件夹下

改动 /etc/profile 中的 PATH,后边追加:/usr/local/openssh/bin

在start_program.sh中添加

/usr/local/openssh/bin/sshd -f /etc/ssh/sshd_config

 

 

 

 

 

### 如何在嵌入式系统中移植和配置SSH服务 #### 1. 移植SSH服务的前提条件 为了成功地将SSH服务移植到嵌入式系统中,需要确保目标设备已经具备基本的操作系统环境和支持网络功能。通常情况下,在嵌入式环境中使用的Linux发行版(如Ubuntu Core或Debian)会提供基础的软件包支持[^1]。 #### 2. 安装OpenSSH服务器 在嵌入式Linux系统中,最常用的SSH实现是OpenSSH。可以通过以下方式安装OpenSSH服务器: 对于基于APT的系统(如Ubuntu),执行以下命令来安装OpenSSH服务器: ```bash sudo apt update sudo apt install openssh-server ``` 此过程会自动下载并安装必要的依赖项[^2]。 #### 3. 配置SSH服务 默认情况下,安装完成后SSH服务会被启用并运行。如果需要自定义配置,则需编辑`/etc/ssh/sshd_config`文件。以下是几个常见的配置选项及其说明: - **Port**: 设置SSH监听端口,默认为22。 - **PermitRootLogin**: 控制是否允许root用户通过SSH登录。 - **PasswordAuthentication**: 启用或禁用密码认证。 - **PubkeyAuthentication**: 启用公钥认证。 修改配置后重启SSH服务以应用更改: ```bash sudo systemctl restart sshd ``` #### 4. 开启防火墙规则 如果嵌入式系统有防火墙保护,需要确保开放SSH所使用的端口(通常是22)。例如,使用UFW工具开启端口: ```bash sudo ufw allow 22/tcp sudo ufw enable ``` #### 5. 测试SSH连接 完成以上步骤后,可以从另一台机器测试SSH连接是否正常工作: ```bash ssh username@embedded_device_ip_address ``` 其中`username`为目标系统的用户名,而`embedded_device_ip_address`则是该设备的IP地址[^2]。 #### 6. 进一步优化与安全措施 考虑到嵌入式系统的特殊性和安全性需求,还可以采取一些额外的安全措施,比如设置密钥验证代替密码验证、定期更新系统补丁以及监控异常访问尝试等[^3]。 ```bash # 创建SSH密钥对 ssh-keygen -t rsa -b 4096 # 将公钥复制至远程主机 ssh-copy-id user@remote_host ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值