这几天都在学习Qt开发,基于正点原子I.MX6U的出厂系统上进行。分两篇记录搭建I.MX6U的Qt开发环境。毕竟太折磨了。
1. 搭建服务器
首先在虚拟机上完成服务端的搭建
1.1 安装SSH步骤:
-
在终端执行
sudo apt-get install ssh
-
启动服务器
/etc/init.d/ssh start
2. openssh移植到开发板上
我用的交叉编译器是arm-linux-gnueabihf-gcc。
2.1 下载源码包
下载openssh-4.6p1.tar.gz、openssl-0.9.8k.tar.gz和zlib-1.2.3.tar.gz这三个源码包,ssh服务需要依赖zlib和ssl库。
- zlib:www.zlib.net/fossils/
- openssl:/source/mirror.html (openssl.org)
- openssh:Index of /pub/OpenBSD/OpenSSH/portable/
2.2 交叉编译
- 在根目录建立目录ssh
- cd 进去后,新建目录compressed(存放源码包),install(软件安装目录),source(源码解压目录)
- 在window上下载完三个压缩包后通过filezila丢到compressed
2.2.1 编译zlib
cd /ssh/source/compressed
tar xvf zlib-1.2.3.tar.gz -C ../source
cd ../source/zlib-1.2.3
./configure --prefix=/ssh/install/zlib-1.2.3
修改Makefile中的信息
原来的代码
CC=gcc
AR=ar rc
CPP=gcc -E
LDSHARED=gcc
修改为:
cc=arm-linux-gnueabihf-gcc
AR=arm-linux-gnueabihf-gcc-ar rc
CPP=arm-linux-gnueabihf-gcc-gcc -E
LDSHARED=arm-linux-gnueabihf-gcc
修改完后执行
make
make install
2.2.2 编译openssl
cd /ssh/source/compressed
tar xvf openssl-0.9.8k.tar.gz -C ../source
cd ../source/openssl-0.9.8k
./Configure --prefix=/home/lasa/ssh/install/openssl-0.9.8k os/compiler:/usr/local/arm/gcc-gnueabihf/bin/arm-linux-gnueabihf-gcc
//gcc这里要填绝对路径
执行
make
make install
2.2.3 编译openssh
cd /ssh/source/compressed
tar xvf openssh-4.6p1.tar.gz -C ../source
cd ../source/openssh-4.6p1
./configure --host=arm-linux --with-libs --with-zlib=/home/lasa/ssh/install/zlib-1.2.3
--with-ssl-dir=/home/lasa/ssh/install/openssl-0.9.8k
--disable-etc-default-login
CC=arm-linux-gnueabihf-gcc AR=arm-linux-gnueabihf-ar
执行完后执行make
,不要执行make install
3. 安装SSH到开发板上
在Ubuntu的ssh/source/openssh-4.6p1下新建目录 bin,etc,libexec,sbin
3.1 生成key文件
cd 到openssh-4.6p1中,
ssh-keygen -t ecdsa -f ssh_host_ecdsa_key -N ""
ssh-keygen -t rsa -f ssh_host_rsa_key -N ""
ssh-keygen -t dsa -f ssh_host_dsa_key -N ""
3.2 分类文件
将openssh-4.6p1下编译好的文件分类
cp scp sftp ssh ssh-add ssh-agent ssh-keygen ssh-keyscan ../../source/openssh-4.6p1/bin/
cp moduli ssh_config sshd_config ../../ source/openssh-4.6p1/etc
cp sftp-server ssh-keysign ../../ source/openssh-4.6p1/libexec/
cp sshd ../../ source/openssh-4.6p1/sbin
cp ssh_host_*_key ../../ source/openssh-4.6p1/etc
放置好后打包并传到开发板上
tar zcvf openssh.tar.bz2 ./*
#开发板上:前面是用户名@Ubuntu IP + 文件路径,后面是开发板路径
scp lasa@192.168.10.100:/home/lasa/ssh/source/openssh-4.6p1/openssh.tar.bz2 ./
3.3 开发板上解压安装
- 解压到开发板的usr/local下,没有的话新建
tar xvf openssh.tar.bz2 -C /usr/local
另外,在板子上新建一个空文件夹:
mkdir /var/empty
3.3.1 修改开发板上的配置
- 打开/usr/local/etc/sshd_config,将PermitRootLogin yes的注释去掉,如果没有这一句要加上
- 执行
passwd root
增加密码 - 打开/etc/passwd文件,在最后添加上
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
- 打开/etc/init.d/rcS,在最后增加:
/usr/local/sbin/sshd &
,让ssh服务开启后在后台启动。
重启开发板!
3.3.2 测试
执行/usr/local/sbin/sshd
,可能会出错:
Could not load host key: /usr/local/etc/ssh_host_dsa_key
Disabling protocol version 1. Could not load host key
重新生成hostkey文件并放到/usr/local/etc下:
ssh-keygen -t rsa1 -f ssh_host_key -N ""
cp ssh_host_dsa_key ./usr/local/etc/
然后重启ssh服务 /usr/local/sbin/sshd
。完成这些可以通过ps
查看ssh进程是否存在,当然,网上大多数帖子都是到这一步就🆗了。但是我的部署完后很奇怪🤣-----进程里面查不到ssh相关的,而且,重启服务也不冒错。。。然后又重装了几遍。。
在ubuntu上面ssh远程连接板子的时候还出现错误
ssh root@192.168.8.109
Unable to negotiate with 192.168.8.109 port 22: no matching host key type found. Their offer: ssh-rsa
在看了很多帖子之后,我总算是找到了目前可以解决的办法----》SSH 无法协商错误的解决方案 - 信息安全问题 (infosecmatter.com)
通过在命令行上向客户端添加一个额外的选项:
ssh -oHostKeyAlgorithms=+ssh-rsa root@192.168.10.115
结果就是每次远程连接的时候就需要填巨长。。还没开始就累了,所以修改了config,把这些信息都弄进去
cd ~/.ssh
gedit config
#config里:
Host myhost
HostName 192.168.10.115
Port 22
User root
HostKeyAlgorithms=+ssh-rsa
这样执行 ssh myhost
既可远程连接开发板。
Ps: 开发板的静态ip设置也记一下:
#在出厂文件系统里添加一下文件
vi /etc/rc.local
#设置eth0的静态ip地址
PATH=/sbin:/bin:/usr/sbin:/usr/bin
ifconfig eth0 192.168.1.115 netmask 255.255.255.0
route add default gw 192.168.1.1
echo "nameserver 114.114.114.114" > /etc/resolv.conf