一、源码下载
zlib:zlib-1.3.1.tar.xz
openssl:openssl-0.9.8d.tar.gz
openssh:openssh-4.6p1.tar.gz
二、交叉编译
1、zlib
编译参考这里
2、openssl
tar -xf openssl-0.9.8d.tar.gz
./Configure --prefix=/opt/ssh/openssl os/compiler:arm-linux-gcc
make -j8
sudo make instal
3、openssh
tar -xf openssh-4.6p1.tar.gz
./configure --host=arm-linux --with-libs --with-zlib=/opt/ssh/zlib \
--with-ssl-dir=/opt/ssh/openssl --disable-etc-default-login \
CC=arm-linux-gcc AR=arm-linux-ar
make -j8
不用make install
完成后当前目录下会生成SSH可执行文件
三、安装SSH
1、配置文件
首先,确保目标板上有以下目录
/usr/local/bin/
/usr/local/sbin/
/usr/local/etc/
/usr/local/libexec/
/var/run/
/var/empty/
chmod 755 /var/empty
然后,拷贝相关文件到开发板
复制 sshd 到开发板的 /usr/local/sbin/
复制 scp sftp ssh ssh-add ssh-agent ssh-keygen ssh-keyscan 到开发板的 /usr/local/bin
复制 sftp-server ssh-keysign 到 /usr/local/libexec
复制 sshd_config ssh_config 到 /usr/local/etc/
2、生成Key文件
在开发板上,进入/usr/local/etc/目录,执行以下命令生成key:
../bin/ssh-keygen -t rsa1 -f ssh_host_key -N ""
../bin/ssh-keygen -t rsa -f ssh_host_rsa_key -N ""
../bin/ssh-keygen -t dsa -f ssh_host_dsa_key -N ""
修改当前目录下sshd_config文件,将 /etc/ssh 改为 /usr/local/etc
# HostKey for protocol version 1
HostKey /etc/ssh/ssh_host_key 》》》 HostKey /usr/local/etc/ssh_host_key
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key 》》》 HostKey /usr/local/etc/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key 》》》 HostKey /usr/local/etc/ssh_host_dsa_key
3、设置系统时间
如果开发板时间是1970需要设置为当前时间,否则ssh登录一直报错:
date -s "2024-05-09 16:21"
4、设置root密码
passwd root
5、添加用户
复制PC机 /etc 下的 passwd shadow group 到开发板 /etc 下,并将passwd文件里的 /bin/bash 改为 /bin/sh .
.
四、启动SSH
绝对路径启动sshd
/usr/local/sbin/sshd
可能出现的错误:
Permissions 0755 for '/usr/local/etc/ssh_host_dsa_key' are too open.
//将开发板/usr/local/etc/下的key文件 ssh_host_* 权限改为700。
Permission denied (publickey,password,keyboard-interactive).
//打开开发板/usr/local/sshd_config,将PermitRootLogin yes前的注释“#”号去掉。
主机: $ ssh root@10.10.82.45(开发板的ip)//root密码就是开发板root密码,如果没有设置,用passwd root设置。
cms.pod around line 457: Expected text after =item, not a number
cms.pod around line 461: Expected text after =item, not a number
cms.pod around line 465: Expected text after =item, not a number
cms.pod around line 470: Expected text after =item, not a number
cms.pod around line 474: Expected text after =item, not a number
POD document had syntax errors at /usr/bin/pod2man line 69.
make: *** [install_docs] Error 1
解决:
sudo rm -f /usr/bin/pod2man
Privilege separation user sshd does not exist
解决:
修改/etc/passwd文件,在其中加入
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
觉得有帮助的话,打赏一下呗。。