本帖最后由 sandman78 于 2017-6-15 16:00 编辑
开发板上没有ssh, 为了方便开发,编译安装Openssh到开发板
编译器
源码
编译
默认全部安装到/home/install目录
编译zlib$ CC=arm-linux-gnueabihf-gcc AR=arm-linux-gnueabihf-ar LDSHARED=arm-linux-gnueabihf-gcc ./configure --prefix=/home/install/zlib
$ make
$ make install
编译openssl$ ./Configure --prefix=/home/install/openssl os/compiler:arm-linux-gnueabihf-gcc
$ make
$ make install
编译openssh$ ./configure --host=arm-linux-gnueabihf --with-libs --with-zlib=/home/install/zlib --with-ssl-dir=/home/install/openssl --disable-etc-default-login
$ make
安装到开发板
建立目录确保目标板上有以下目录,若没有,则新建:
/usr/local/bin
/usr/local/etc
/usr/libexec
/var/run
/var/empty
复制文件scp、sftp、ssh sshd、ssh-add、ssh-agent、ssh-keygen、ssh-keyscan共8个文件拷贝到目标板/usr/local/bin
moduli、ssh_config、sshd_config共3个文件拷贝到目标板 /usr/local/etc
sftp-server、ssh-keysign 共2个文件拷贝到目标板 /usr/libexec
修改/etc/passwd
打开 /etc/passwd 文件,在最后添加下面这一行:
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/***in/nologin
如果开发板的 root 用户还没有密码,键入以下命令然输入两次密码来修改,否其他设备无法连接
$ passwd root
sshd 自启动建立启动脚本$ vi /etc/init.d/sshd.sh
- #!/bin/sh
- if [ ! -x /usr/local/bin/sshd ]
- then
- exit 0
- fi
- if [ "$1" = "stop" -o "$1" = "restart" ]
- then
- echo "Stopping the ssh server: "
- killall sshd
- fi
- if [ "$1" = "start" -o "$1" = "restart" ]
- then
- # assume if one key is missing, all are
- if [ ! -f /usr/local/etc/ssh_host_rsa_key ]
- then
- echo "Generating keys for the ssh server: "
- /usr/local/bin/ssh-keygen -t rsa -f /usr/local/etc/ssh_host_rsa_key -N ""
- /usr/local/bin/ssh-keygen -t dsa -f /usr/local/etc/ssh_host_dsa_key -N ""
- /usr/local/bin/ssh-keygen -t ecdsa -f /usr/local/etc/ssh_host_ecdsa_key -N ""
- /usr/local/bin/ssh-keygen -t dsa -f /usr/local/etc/ssh_host_ed25519_key -N ""
- fi
- for i in ssh_host_rsa_key ssh_host_dsa_key ssh_host_ecdsa_key ssh_host_ed25519_key
- do
- chmod 600 /usr/local/etc/$i
- done
- #echo "Starting the ssh server:"
- /usr/local/bin/sshd
- fi
添加执行权限$ chmod +x sshd.sh
建立软链接$ ln -s /etc/rcS.d/S60sshd.sh /etc/init.d/sshd.sh
到此重启后就可以甩掉串口线,用ssh登陆开发板了
sftp$ vi /usr/local/etc/sshd_config
修改包含sftp行
Subsystem sftp /usr/libexec/sftp-server
到此重启后就可以用sftp和开发板传输文件了