SSH is the recommended way to interact with Snappy devices. SSH is normally enabled by default in Ubuntu Core Image, but is disabled by default in normal product builds. This is because we don’t want our devices to be accessed by users over SSH. So how do we open our SSH interface?

\

In order to be able to SSH access, one way we can do this is to start SSHD manually, or you want SSHD to start automatically every time you start. This way we don’t have to manually start our SSHD every time. If this is the case, we must modify our image. We must remove “/etc/ssh/sshd_not_to_be_run” from filesystem.

The simplest way to modify filesystem is to mount an image that can perform DD as a loop device in our host. To do this, we use kparkx to register our.img file:

$ sudo kpartx -av yourimage.img

add map loop0p1 (252:3): 0 131072 linear /dev/loop0 8192
add map loop0p2 (252:4): 0 2097152 linear /dev/loop0 139264
add map loop0p3 (252:5): 0 2097152 linear /dev/loop0 2236416
add map loop0p4 (252:6): 0 3282944 linear /dev/loop0 4333568
Copy the code

\

The above command creates the items needed for the mapped loop device and corresponding boot. System-a and system-b are created in our /dev/disk/by-label-/ directory, respectively. We need to mount the two partitions and delete the files in them /etc/ssh/sshd_not_to_be_run

\

# mount and enable ssh on system-a partition
$ sudo mount /dev/disk/by-label/system-a /mnt
$ sudo rm -f /mnt/etc/ssh/sshd_not_to_be_run
$ sudo umount /mnt

# mount and enable ssh on system-b partition
$ sudo mount /dev/disk/by-label/system-a /mnt
$ sudo rm -f /mnt/etc/ssh/sshd_not_to_be_run
$ sudo umount /mnt
Copy the code

\

Finally, we use kparkx to unregister our image:

$ sudo kpartx -dv  yourimage.img
del devmap : loop0p4
del devmap : loop0p3
del devmap : loop0p2
del devmap : loop0p1
loop deleted : /dev/loop0
Copy the code

\

Select and we get an image that we want. This image can have SSH functionality. See the article “How to Install Snappy Ubuntu on RaspBerry PI” to install it on our devices.




\