在编译海思SDK时,会自动编译openssl,zlib,故无需重复编译这两者。
本文下载openssh-7.3p1版本,将其下载至虚拟机
tar -xvf openssh-7.3p1.tar.gz
./configure --host=arm-linux --prefix=/usr/local/openssh --with-zlib=/hi3798/HiSTBLinuxV100R005C00SPC050/out/hi3798mv200/hi3798mv2dmo/obj/source/component/zlib/release --with-ssl-dir=/hi3798/HiSTBLinuxV100R005C00SPC050/out/hi3798mv200/hi3798mv2dmo/obj/source/component/openssl/release --disable-etc-default-login --disable-strip CC=arm-histbv320-linux-gcc AR=arm-histbv320-linux-ar
使前缀--prefix=/usr/local/openssh,因为最后openssh使安装在开发板的这个目录下,/hi3798/HiSTBLinuxV100R005C00SPC050/out/hi3798mv200/hi3798mv2dmo/obj/source/component/zlib/release是zlib在虚拟机下的安装目录,--with-ssl-dir=/hi3798/HiSTBLinuxV100R005C00SPC050/out/hi3798mv200/hi3798mv2dmo/obj/source/component/openssl/release 是ssl在虚拟机下的安装目录。
然后在openssh源目录下执行make
make
最终会在该目录下生成一下12个文件
scp sftp ssh ssh-add ssh-agent ssh-keygen ssh-keyscan moduli ssh_config sshd_config sftp-server ssh-keysign
到目录下/hi3798/HiSTBLinuxV100R005C00SPC050/source/rootfs/scripts目下解压rootfs.tar.bz2,得到rootfs文件夹,并且在rootfs文件夹下创建一下目录
/usr/local/openssh/bin
/usr/local/openssh/etc
/usr/local/libexec
/var/run
/var/empty
将以下文件拷贝到/hi3798/HiSTBLinuxV100R005C00SPC050/source/rootfs/scripts/rootfs/usr/local/openssh/bin目录下:
并且在该目录下建立软连接
ln -snf /usr/local/openssh/bin/scp
ln -snf /usr/local/openssh/bin/sftp
ln -snf /usr/local/openssh/bin/ssh
ln -snf /usr/local/openssh/bin/ssh-add
ln -snf /usr/local/openssh/bin/ssh-agent
ln -snf /usr/local/openssh/bin/ssh-keygen
ln -snf /usr/local/openssh/bin/ssh-keyscan
ln -snf /usr/local/openssh/bin/sshd
将moduli ssh_config sshd_config三个文件拷贝到/hi3798/HiSTBLinuxV100R005C00SPC050/source/rootfs/scripts/rootfs/usr/local/openssh/etc目录下
并且执行以下命令生成证书密码对:
ssh-keygen -t rsa -f ssh_host_rsa_key -N ""
ssh-keygen -t dsa -f ssh_host_dsa_key -N ""
ssh-keygen -t ecdsa -f ssh_host_ecdsa_key -N ""
ssh-keygen -t ed25519 -f ssh_host_ed25519_key -N ""
至此,/hi3798/HiSTBLinuxV100R005C00SPC050/source/rootfs/scripts/rootfs/usr/local/openssh/etc目录下有以下文件
将sshd_config中的PermitRootLogin no改为PermitRootLogin yes,将“Subsystem sftp /usr/libexec/sftp-server”改为“Subsystem sftp /usr/local/libexec/sftp-server”
将sftp-server ssh-keysign拷贝至/hi3798/HiSTBLinuxV100R005C00SPC050/source/rootfs/scripts/rootfs/usr/local/libexec
另外,在/hi3798/HiSTBLinuxV100R005C00SPC050/source/rootfs/scripts/rootfs/etc/group中添加
sshd:x:1001:sshd
在/hi3798/HiSTBLinuxV100R005C00SPC050/source/rootfs/scripts/rootfs/etc/gshadow中添加
sshd:!::sshd
在/hi3798/HiSTBLinuxV100R005C00SPC050/source/rootfs/scripts/rootfs/etc/passwd中添加
sshd:x:1001:1001:sshd privsep:/var/empty:/bin/ssh
在/hi3798/HiSTBLinuxV100R005C00SPC050/source/rootfs/scripts/rootfs/etc/shadow中添加
sshd:BsmGtKsu9a9a6:15506:5:99999:7:5:20000:
在/hi3798/HiSTBLinuxV100R005C00SPC050/source/rootfs/scripts/rootfs/autorun.sh中添加
#!/bin/sh
#addgroup sshd
#adduser -G sshd -g 'sshd privsep' -h /var/empty -p 123456 -s /bin/ssh sshd
#useradd -G sshd -g 'sshd privsep' -h /var/empty -p 123456 -s /bin/ssh sshd
echo root:123456 | chpasswd root
sed -i 's|:0:5:99999:7:5:20000:|:15506:5:99999:7:5:20000:|' /etc/shadow
chown -R root.root /var/empty
chmod 744 /var/empty
/usr/local/openssh/bin/sshd
echo "sleep 5"
在rcS末尾添加
cd /
chmod +x autorun.sh
./autorun.sh