×
单片机 > 单片机程序设计 > 详情

TQ2440下的openssh移植

发布时间:2020-08-26 发布时间:
|

移植ssh到arm 今天在internet上参考了几位前辈文章, 将ssh移植到了TQ2440的arm板上, 现在不需要用minicom来控制uclinux了。 板子上的串口终于可以接上采集器。 主要参考文章:


http://blog.chinaunix.net/u1/43047/showart_371372.html

http://blog.chinaunix.net/u2/63379/showart_513655.html

 


1.下载需要的源码:

    mkdir -p ~/arm/fs ;mkdir -p ~/arm/source

    下载zlib:  wget -c http://www.zlib.net/zlib-1.2.3.tar.gz

    下载ssl:  wget -c http://www.openssl.org/source/openssl-0.9.8d.tar.gz

    下载ssh: wget -c http://mirror.mcs.anl.gov/openssh/portable/openssh-4.6p1.tar.gz



2.编译:

    cd ~/arm/source


    (1) 编译zlib:

     tar zxvf zlib-1.2.3.tar.gz -C .

     cd zlib-1.2.3/

     ./configure --prefix=/home/itlanger/arm/fs/zlib-1.2.3

    修改Makefile:

       CC=gcc 改为: 

       CROSS=/usr/local/arm/3.4.1/bin/arm-linux-

       CC=$(CROSS)gcc 

       LDSHARED=gcc 改为: LDSHARED=$(CROSS)gcc

       CPP=gcc -E   改为:  CPP=$(CROSS)gcc -E

       AR=ar rc     改为: AR=$(CROSS)ar rc

  开始编译: make;

           make install


   (2)  编译openssl:

       tar zxvf openssl-0.9.8d.tar.gz

      ./configure --prefix=/home/itlanger/arm/fs/openssl-0.9.8d

     os/compiler:/usr/local/arm/3.4.1/bin/arm-linux-gcc

    make

    make install


   (3) 编译openssh:

      tar zxvf openssh-4.6p1.tar.gz

      cd openssh-4.6p1/

      ./configure --host=arm-linux --with-libs --with-zlib=/home/itlanger/arm/fs/zlib-1.2.3

         --with-ssl-dir=/home/itlanger/arm/fs/openssl-0.9.8d --disable-etc-default-login     

         CC=/usr/local/arm/3.4.1/bin/arm-linux-gcc AR=/usr/local/arm/3.4.1/bin/arm-linux-ar

      make

      ##不要make install


3.安装

    

    (1) 将 openssh-4.6p1目录下的 sshd 拷贝到 目标板的/usr/sbin目录下

    (2) 再copy scp  sftp  ssh  ssh-add  ssh-agent  ssh-keygen  ssh-keyscan  到目标板/usr/local/bin目录下

            copy sftp-server  ssh-keysign    到/usr/local/libexec

       

    (3) 在目标板下:

        mkdir -p /usr/local/etc/  

        然后将openssh下的sshd_config,ssh_config 拷贝到该目录下


        mkdir -p /var/run; mkdir -p /var/empty/sshd 

        chmod 755 /var/empty     

    (4)在主机上:

         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_* 几个文件copy到目标板的 /usr/local/etc/目录下(可使用cp ssh_host_* /usr/local/etc/命令拷贝到目标板)

(5) 添加用户:

将主机上 /etc/目下的passwd, shadow, group 三个文件copy到目标板的 /etc目录下, 同时记得将passwd的最后 /bin/bash 该为 /bin/sh

//这一步以后,开发板上的用户结构与你本机的结构就是一样的了,所以在cp之前先把你自己的root密码设好

//#passwd设置root密码,然后在把上面3个文件cp到开发板/etc下

      其实可以删除不需要的一些用户。

      这一步也可以这样,在目标板的passwd中添加sshd用户:

      sshd:x:110:65534::/var/run/sshd:/usr/sbin/nologin

      在shadow中也添加对应的项就行了:

      sshd:!:14069:0:99999:7:::

     

4.测试

     目标板启动sshd:  # /usr/sbin/sshd

//在开发板上运行这个命令的时候可能会提示

//Privilege separation user sshd does not exist

//需要在开发板的系统里adduser shhd

//或者在 /etc/passwd 中添加下面这一行


sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin


主机: $ ssh root@192.168.0.34(开发板的ip)//root密码就是你本机上root的密码


ps: 红色的那些代表让arm做ssh server时必须的

------------------------------------------------

下边进行免密码登录设置:

cp(主机) root/.ssh/id_dsa.pub 到 (开发板)/.ssh/authorized_keys

---------------------------------------------------

如何让板子开机以后自动启动sshd服务:


添加:/etc/rc.d/init.d/sshd


#!/bin/sh                                                                       

base=sshd                                                                       

# See how we were called.                                                       

case "$1" in                                                                    

  start)                                                                        

                /usr/sbin/$base                                                     

        ;;                                                                      

  stop)                                                                         

        pid=`/bin/pidof $base`                                                  

        if [ -n "$pid" ]; then                                                  

                kill -9 $pid                                                    

        fi                                                                      

        ;;                                                                      

esac                  


在更改/etc/init.d/rcS,添加:


mkdir -p /var/empty/sshd

/etc/rc.d/init.d/sshd start


然后重启机器,一切OK!



我移植成功后出现以下问题:


Could not load host key: /etc/ssh/ssh_host_rsa_key


问题的解决


症状:


用命令/usr/sbin/sshd启动sshd时出现:


系统提示“Could not load host key: /etc/ssh/ssh_host_key


问题所在:


    1、系统丢失了ssh_host_dsa_key和ssh_host_rsa_key


    2、用户没有权限访问这两个key


解决办法如下:


1、系统丢失了两个key时:


在终端中输入:ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key重新建立ssh_host_dsa_key文件


以下是返回信息


Generating public/private dsa key pair.


Enter passphrase (empty for no passphrase):(直接回车)


Enter same passphrase again:


Your identification has been saved in /etc/ssh/ssh_host_dsa_key.


Your public key has been saved in /etc/ssh/ssh_host_dsa_key.pub.


The key fingerprint is:


xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx root@localhost.localdomain


在终端中输入:ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key重新建立ssh_host_rsa_key文件


以下是返回信息


Generating public/private rkey pair.


Enter passphrase (empty for no passphrase):(直接回车)


Enter same passphrase again:


Your identification has been saved in /etc/ssh/ssh_host_rsa_key.


Your public key has been saved in /etc/ssh/ssh_host_dsa_rey.pub.


root@localhost.localdomain


现在用


/u


关键字:TQ2440  openssh  移植

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
AVR熔丝位操作时的要点和需要注意的相关事项