移植ssh到arm

来源:互联网 发布:香菜不笑了知乎 编辑:程序博客网 时间:2024/04/29 14:31

我用的是天嵌的TQ2440开发板,但SSH移植不涉及到驱动什么的,所以ARM的板子应该都通用

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/david/fs/zlib-1.2.3
    修改Makefile:
       CC=gcc 改为:
       CROSS=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/david/fs/openssl-0.9.8d os/compiler: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/linksens/tools/fs/zlib-1.2.3
         --with-ssl-dir=/home/david/fs/openssl-0.9.8d --disable-etc-default-login    
         CC=arm-linux-gcc AR=arm-linux-ar
      make
    ##不要make install

这里分享一份我自己编译好的所有文件和配置文件

http://pan.baidu.com/s/1qYpIumS


3. 安装
    
    (1) 将 编译完成目录下的 sshd 拷贝到 目标板的/usr/sbin目录下


    (2) 

mkdir /usr/local/bin

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

mkdir /usr/local/libexec
          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_* 多个文件复制到目标板的 /usr/local/etc/目录下

(打包的文件中也有已经生成好的,在key文件夹下

  (5) 添加用户:
    将主机上 /etc/目下的 passwd, shadow, group 三个文件copy到目标板的 /etc目录下, 同时记得将passwd的最后 /bin/bash 该为 /bin/sh (在打包的文件中也有,在etc目录下)
    其实可以删除不需要的一些用户。
     
4.测试

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

# passwd root    给root设个密码,否则可能没法登陆


     客户主机: $ ssh root@192.168.237.239

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

以上参考:http://hi.baidu.com/fcni_cn/blog/item/4a3ee7115e08cd18b8127b4f.html


下面的一定要继续看
遇到问题:
1 Permissions 0644 for '/usr/local/etc/ssh_host_key' are too open
此为文件的权限问题,解决方法为:

# cd /usr/local/etc

# ls

moduli ssh_host_dsa_key ssh_host_key ssh_host_rsa_key sshd_config

ssh_config ssh_host_dsa_key.pub ssh_host_key.pub ssh_host_rsa_key.pub

# ls -l

total 194

-rwxr-xr-x 1 bin bin 88039 Nov 21 2002 moduli

-rwxr-xr-x 1 bin bin 1144 Nov 21 2002 ssh_config

-rwxr-xr-x 1 root other 672 Dec 19 13:55 ssh_host_dsa_key

-rwxr-xr-x 1 root other 600 Dec 19 13:55 ssh_host_dsa_key.pub

-rwxr-xr-x 1 root other 525 Dec 19 13:54 ssh_host_key

-rwxr-xr-x 1 root other 329 Dec 19 13:54 ssh_host_key.pub

-rwxr-xr-x 1 root other 887 Dec 19 13:55 ssh_host_rsa_key

-rwxr-xr-x 1 root other 220 Dec 19 13:55 ssh_host_rsa_key.pub

-rwxr-xr-x 1 bin bin 2470 Nov 21 2002 sshd_config

# chmod 0644 *

# ls -l

total 194

-rw-r--r-- 1 bin bin 88039 Nov 21 2002 moduli

-rw-r--r-- 1 bin bin 1144 Nov 21 2002 ssh_config

-rw-r--r-- 1 root other 672 Dec 19 13:55 ssh_host_dsa_key

-rw-r--r-- 1 root other 600 Dec 19 13:55 ssh_host_dsa_key.pub

-rw-r--r-- 1 root other 525 Dec 19 13:54 ssh_host_key

-rw-r--r-- 1 root other 329 Dec 19 13:54 ssh_host_key.pub

-rw-r--r-- 1 root other 887 Dec 19 13:55 ssh_host_rsa_key

-rw-r--r-- 1 root other 220 Dec 19 13:55 ssh_host_rsa_key.pub

-rw-r--r-- 1 bin bin 2470 Nov 21 2002 sshd_config

# chmod 0600 ssh_host_dsa_key ssh_host_rsa_key

# ls -l

total 194

-rw-r--r-- 1 bin bin 88039 Nov 21 2002 moduli

-rw-r--r-- 1 bin bin 1144 Nov 21 2002 ssh_config

-rw------- 1 root other 672 Dec 19 13:55 ssh_host_dsa_key

-rw-r--r-- 1 root other 600 Dec 19 13:55 ssh_host_dsa_key.pub

-rw------- 1 root other 525 Dec 19 13:54 ssh_host_key

-rw-r--r-- 1 root other 329 Dec 19 13:54 ssh_host_key.pub

-rw------- 1 root other 887 Dec 19 13:55 ssh_host_rsa_key

-rw-r--r-- 1 root other 220 Dec 19 13:55 ssh_host_rsa_key.pub

-rw-r--r-- 1 bin bin 2470 Nov 21 2002 sshd_config

2 在ssh目标机时出现

ssh root@192.168.237.239

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!

Someone could be eavesdropping on you right now (man-in-the-middle attack)!

It is also possible that the RSA host key has just been changed.

The fingerprint for the RSA key sent by the remote host is

97:ff:ec:78:48:69:c0:61:1d:82:9b:6c:2e:6b:6b:46.

Please contact your system administrator.

Add correct host key in /root/.ssh/known_hosts to get rid of this message.

Offending key in /root/.ssh/known_hosts:11

RSA host key for 192.168.237.239 has changed and you have requested strict checking.

Host key verification failed.

警告中已经说的很清楚了,清空/root/.ssh/known_hosts(主机而非目标机)即可

[root@localhost ~]#ssh-keygen -R 192.168.237.239

删除单个的公钥!

3、sftp无法使用

通常情况下,sftp无法启动是因为ssh启动时找不到sftp-server,Subsystem sftp配置选项就是sftp-server的位置声明,路径与开发板实际sftp-server所在位置修改为一致,重启sshd,sftp服务器就可以正常调用了。

/usr/local/etc/sshd_config文件中,将Subsystem sftp修改为如下所示:

Subsystem sftp /usr/local/libexec/sftp-server


4、添加开机启动

将sshd启动命令添加到开机引导脚本

在/etc/init.d/rcS文件尾添加一行:/usr/sbin/sshd 即可


0 0
原创粉丝点击