openssh arm linux 编译,openssh编译安装到ARM嵌入式系统中

目录

一.SSHD编译(此步骤在虚拟机上执行)

1.1 在/root/目录下创建ssh目录

1.2 交叉编译zlib

1.3交叉编译openssl

1.4交叉编译openssh

二.移植(此步骤在开发板上执行)

2.1 在开发板上建立需要的目录

2.2 下面是在开发板上操作

2.3修改sshd_config

三、加入自启动脚本

参考:

注:如果想自行编译移植,即可从第一步开始;若已有sshd 、sftp-server、密钥等文件则直接进行第二个步骤;相关源码及编译后的文件在附件中可见。

一.SSHD编译(此步骤在虚拟机上执行)

源码包:zlib-1.2.3.tar.bz2

openssl-0.9.81.tar.gz

openssh-4.6p1.tar.gz

说明:本次只移植SSH的服务端,客户端相关程序和配置文件不拷贝到开发板。

1.1 在/root/目录下创建ssh目录

#mkdir /root/ssh

#cd /root/ssh

#mkdir compressed install source注:compressed用于存放源码包

install软件安装目录

source源码包解压目录

将三个源码包拷贝到compressed目录下。

1.2交叉编译zlib

# tar -jxvf zlib-1.2.3.tar.bz2  -C  ../source

# cd ../source/zlib-1.2.3

# ./configure --prefix=/root/ssh/install/zlib-1.2.3

# vi Makefile       //修改Makefile中的某些变量值,指定自己的交叉编译工具

CC=arm-linux-gnueabihf-gcc

CPP=arm-linux-gnueabihf-gcc -E

AR=arm-linux-gnueabihf-ar rc

LDSHARED=arm-linux-gnueabihf-gcc

保存退出执行make

make install

1.3交叉编译openssl

# cd /root/ssh/compressed/

# tar -zxvf openssl-0.9.81.tar.gz  -C  ../source

# cd ../source/openssl-0.9.81

#./Configure  --prefix=/root/ssh/install/openssl-0.9.81  os/compiler:arm-linux-gnueabihf-gcc

执行make(如果遇到错误输入rm -f /usr/bin/pod2man)

make install(如果遇到错误输入rm -f /usr/bin/pod2man)

1.4交叉编译openssh

# cd /root/ssh/compressed

# tar -zxvf openssh-4.6p1.tar.gz  -C ../source

# cd ../source/openssh-4.6p1

#./configure --host=arm-linux-gnueabihf --with-libs                                 --with-zlib=/root/ssh/install/zlib-1.2.3/ --with-ssl-dir=/root/ssh/install/openssl-0.9.81 --disable-etc-default-login CC=arm-linux-gnueabihf-gcc AR=arm-linux-gnueabihf-ar

#make注:不要make install

这时在/root/ssh/source/ openssh-4.6p1/目录下生成了sshd、sftp-server、密钥等文件。

可以用strip工具把sshd体积变小,以节省空间,操作如下:

#arm-linux-gnueabihf-strip -s sshd

还需要建立密钥(用ssh-keygen工具):

#ssh-keygen -t rsa1 -f ssh_host_key -N ""

#ssh-keygen -t rsa -f ssh_host_rsa_key -N ""

#ssh-keygen -t dsa -f ssh_host_dsa_key -N ""

会生成这六个密钥文件:

ssh_host_dsa_key

ssh_host_dsa_key.pub

ssh_host_key

ssh_host_key.pub

ssh_host_rsa_key

ssh_host_rsa_key.pub

二.移植(此步骤在开发板上执行)

2.1 在开发板上建立需要的目录

#mkdir -p /usr/local/etc

#mkdir -p /var/run /var/empty/sshd  并设定权限chmod 755 /var/empty

把在虚拟机下 /root/ssh/source/openssh-4.6p1生成的服务端相关文件拷贝到开发板相应目录下:

sshd和 sftp-server复制到开发板的/sbin/目录下

生成的六个密钥文件和sshd_config复制到/usr/local/etc/目录下

进入/usr/local/etc/目录下,修改权限:

# chmod 0644 *

# chmod 0600 ssh_host_dsa_key  ssh_host_key  ssh_host_rsa_key

2.2 下面是在开发板上操作

修改/etc/目录下的passwd和group文件,添加sshd用户和组

#vi /etc/passwd

在最后一行添加sshd:*:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

保存退出。

#vi /etc/group

在最后一行添加sshd:*:74:

保存退出。

2.3修改sshd_config

分别去掉下列语句前的注释号(即去掉#号)并修改为:

PermitRootLogin    yes―――――允许根用户登陆

PermitEmptyPasswords yes――――允许使用空密码

UsePrivilegeSeparation   no――――把安全级别降低,因为不会连接互联网

同时修改sftp-server的存放路径为 /sbin/sftp-server

a163d8b7b80335f2b6cd342aa1d31615.png

运行sshd时要用绝对路径

#/sbin/sshd

这样可以在windows下用ssh客户端进行连接了。

三、加入自启动脚本

/etc/init.d目录下新建sshd文件

#! /bin/sh

sshd=/sbin/sshd

test -x "$sshd" || exit 0

case "$1" in

start)

echo -n "Starting sshd daemon"

start-stop-daemon --start --quiet --exec $sshd -b

echo "."

;;

stop)

echo -n "Stopping sshd"

start-stop-daemon --stop --quiet --exec $sshd

echo "."

;;

restart)

echo -n "Stopping sshd"

start-stop-daemon --stop --quiet --exec $sshd

echo "."

echo -n "Waiting for sshd to die off"

for i in 1 2 3 ;

do

sleep 1

echo -n "."

done

echo ""

echo -n "Starting sshd daemon"

start-stop-daemon --start --quiet --exec $sshd -b

echo "."

;;

*)

echo "Usage: /etc/init.d/sshd {start|stop|restart}"

exit 1

esac

exit 0

进入/etc/init.d目录执行命令

cd /etc/init.d

ln -sf ../init.d/sshd ../rc5.d/S30sshd

ln -sf ../init.d/sshd ../rc3.d/S30sshd

即可实现开机自动启动sshd服务。

源码下载: https://download.csdn.net/download/v6543210/10746939

参考:

1.Linux嵌入式学习-交叉编译openssl

https://www.cnblogs.com/ynxf/p/6375091.html

linux系统的7种运行级别

https://blog.csdn.net/ccfxue/article/details/52767863

/etc/rc.d/init.d自启动程序说明

https://blog.csdn.net/xysoul/article/details/44956525

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值