Copy Files to Target Board with Dropbear
I got a board with a minimal rootfs, I don’t know how it was created, I have no source code and the rootfs is squashfs, so nothing can be changed, the good thing is there is a mtd partition that I can put all my stuff to.
The only way to put files to target file system is using tftp which comes with busybox.
I have to cross compile dropbear and put relevant files to that partition, in order to use ssh or scp, there must be a known user in system, simply create user root with this command:
echo root:x:0:0:root:/root:/bin/sh > /etc/passwd
Cross Compiling Dropbear
Grab the latest version of dropbear, and configure it with zlib disabled:
wget -c https://matt.ucc.asn.au/dropbear/releases/dropbear-2020.81.tar.bz2
tar xvf dropbear-2020.81.tar.bz2
cd dropbear-2020.81
CC=arm-linux-gcc ./configure --host=arm-linux --disable-zlib --enable-static
make PROGRAMS="dropbear dropbearkey scp"
Put Dropbear to Board
Find available mtd partition and mount it to /tmp/rootfs
before executing the
following script:
#!/bin/sh
serverip=192.168.0.15
mkdir -p /tmp/rootfs/usr/bin
mount --bind /tmp/rootfs/usr /usr
mkdir -p /tmp/rootfs/etc/dropbear
mount --bind /tmp/rootfs/etc /etc
mkdir /tmp/rootfs/root
mount --bind /tmp/rootfs/root /root
mkdir /tmp/rootfs/root/.ssh/
chmod 700 /tmp/rootfs/root/.ssh/
tftp -g -l /tmp/rootfs/usr/bin/dropbear -r dropbear $serverip
tftp -g -l /tmp/rootfs/usr/bin/dropbearkey -r dropbearkey $serverip
tftp -g -l /tmp/rootfs/usr/bin/scp -r scp $serverip
tftp -g -l /tmp/rootfs/root/.ssh/authorized_keys -r id_rsa.pub $serverip
chmod +x /tmp/rootfs/usr/bin/*
echo root:x:0:0:root:/root:/bin/sh > /etc/passwd
dropbear -BERsg
For debugging, run dropbear in foreground is an good option:
dropbear -BEFRsg
Bonus
In order to export PATH in ssh session, put the following in /etc/profile
:
export PATH=/userdata/usr/bin/:$PATH