User Tools

Site Tools


ssh

This is an old revision of the document!


SSH

Root SSH is not enabled on a stock unit. Root login is closed in the stock sshd_config, and there is no published default password. There are two ways in:

  1. A PROXdongl3 with a [TestMode] EEPROM payload and a FAT USB stick.
  2. An autorun script on the internal init SD card.

The USB route is the easiest. From a checkout of the toolkit linked here, make_dongle.py builds the stick: MBR, one FAT32 partition labeled MP_SD, usb/autorun.sh, a public key as authorized_keys, and a pm3-nodump marker.

./make_dongle.py

With no arguments it lists removable disks and keys. The non-interactive form:

./make_dongle.py --device disk4 --key ~/.ssh/id_ed25519.pub

--github <user> pulls github.com/<user>.keys, --key-url takes an .pub URL, --autodump builds the capture variant, and --dry-run shows the plan. It will not touch the system disk and asks for the device name before erasing. It needs Python 3; on Linux it also needs parted, mkfs.vfat from dosfstools, and lsblk/partprobe/udevadm from util-linux.

By hand, the same stick is:

diskutil eraseDisk FAT32 MP_SD MBRFormat /dev/diskN          # macOS

sudo parted -s /dev/sdX mklabel msdos                        # Linux
sudo parted -s /dev/sdX mkpart primary fat32 1MiB 100%
sudo mkfs.vfat -F 32 -n MP_SD /dev/sdX1

cp usb/autorun.sh /Volumes/MP_SD/autorun.sh
cp ~/.ssh/id_ed25519.pub /Volumes/MP_SD/authorized_keys

The one MBR partition matters. The unit mounts partition 1, and a default GPT layout makes that an empty EFI partition, so the payload never finds the script.

Without a PROXdongl3, put the same script on the init SD card as /init/autorun/95-enable-ssh.sh. The autorun directory runs at boot in filename order.

Access script (init SD)

Put a public key next to the script as authorized_keys. This is the init SD version; the USB version in usb/autorun.sh also turns the watchdog off and logs to pm3-autorun.log. It backs up the stock SSH config, installs the key, and leaves the root filesystem read-only again.

#!/bin/sh
HERE=$(cd "$(dirname "$0")" && pwd)
mount -o remount,rw /
 
[ -f /etc/ssh/sshd_config.stock ] || cp /etc/ssh/sshd_config /etc/ssh/sshd_config.stock
 
{
  echo "Port 22"
  echo "PermitRootLogin yes"
  echo "PubkeyAuthentication yes"
  echo "AuthorizedKeysFile .ssh/authorized_keys"
  echo "Subsystem sftp internal-sftp"
} > /etc/ssh/sshd_config
 
mkdir -p /root/.ssh
cat "$HERE/authorized_keys" > /root/.ssh/authorized_keys
chmod 0700 /root/.ssh
chmod 0600 /root/.ssh/authorized_keys
systemctl enable sshd.socket
systemctl restart sshd.socket
mount -o remount,ro /

The stock config is saved as /etc/ssh/sshd_config.stock. To return a unit to stock, restore that file, remove /root/.ssh/authorized_keys, disable sshd.socket, and remount / read-only.

Copying files

The device has an old OpenSSH. Use legacy scp mode:

scp -O file root@<unit-ip>:/tmp/

Watchdog

nx feeds the PIC32 watchdog. If the script leaves nx stopped, add NxExe watchdog 0; the stock [TestMode] path already does. See [pic32] and [nx].

NxExe watchdog 0

The stock [TestMode] path already does this before running the script.

ssh.1795407144.txt.gz · Last modified: by doof