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 改为:
CC=arm-none-linux-gnueabi-gcc
LDSHARED=gcc 改为:
LDSHARED=arm-none-linux-gnueabi-gcc
CPP=gcc -E 改为: CPP=arm-none-linux-gnueabi-gcc -E
AR=ar rc 改为: AR=arm-none-linux-gnueabi-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
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)在pc主机上:
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_* 6个文件copy到目标板的 /usr/local/etc/目录下
(5) 添加用户:
将主机上/etc/目录下的passwd, 中的sshd用户追加到nas的/etc目录中的passwd中(具体sshd:x:74:74:Privilege-separatedSSH:/var/empty/sshd:/sbin/nologin )同时将passwd的最后/bin/bash 改为/bin/sbin 再将主机中/etc目录下的group文件中的用户也同样追加到nas的/etc目录下的group(sshd:x:74:)文件。
(6)sftp-server路径配置
sshd_config更改
Subsystem sftp /usr/local/libexec/sftp-server
4.测试
目标板启动sshd: # /usr/sbin/sshd
主机: $ ssh [email protected]
遇到问题:
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_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目标机时出现
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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.使用ssh sftp连接时SSH出现以下错误:Exit value 0 was returned. Most likely the sftp-server is not in the path of the user on the server-side
解决办法:
查看/etc/ssh/sshd-config文件的最后一行是否正确:
Subsystem sftp /usr/libexec/openssh/sftp-server
路径应为实际sftp-server的路径,修改过来就好了!(重启机器)