I have a computer with an industrial control type motherboard with no video output ports or video cards.

Ubuntu 18.04 server OS boots from a Compact-Flash drive. I installed the OS via cloning.

I would like to add an ssh server to the OS, by adding it to the disk.

The ssh-server was not installed at the time of server OS installation.

How do I add an ssh-server to a bootable hard drive?

  • Maybe, the boot disk a a compact flash, for an industrial control type motherboard. I could clone it to a hard drive, boot it, install ssh, and clone it back to the flash. That seems pretty convoluted. I could try to boot via usb card reader, that might work. A third option: I use a micro controler to give shell commands, emulating a keyboard to install and set up ssh-server. All of those seem like overly complex. I was thinking if I could just add some files for ssh server, and tell it to run on boot that would be simpler. – j0h Feb 10 at 21:52
  • Does my answr solve your problem? – user68186 yesterday

This method of openssh-server installation uses the chroot command to gain access to the files in the compact flash (CF). Once the chroot command is issued, the running Ubuntu treats the CF's / as its own. Commands run in a chroot environment will affect the CF system's filesystems and not those of the running Ubuntu.

Step 1: Preliminary

  • Boot to the Ubuntu desktop in your computer. The running desktop version of Ubuntu should be 64bit (not 32bit) if the CF system is 64 bit, and vice versa. If one is 64bit and the other 32bit, then boot a Live USB (Try Ubuntu without installing) that matches the headless system intalled in the CF.

  • Insert the CF drive in the CF card reader in the desktop computer. Unmount any partitions that are automatically mounted. We will mount them soon using different mount-points.

  • Open a terminal using Ctrl+Alt+T.

  • Determine the normal system partition in the CF drive. The following commands may be helpful. The fdisk switch is a lowercase "L".

    sudo fdisk -l sudo blkid df -Th

Step 2: Mount CF drive's Partitions and chroot

  • Mount your normal system partition. X is the drive letter. Y is the partition number: Substitute the correct partition: sda1, sdb5, etc.

    sudo mount /dev/sdXY /mnt

  • Only if you have a separate boot partition (where sdXY is the /boot partition designation):

    sudo mount /dev/sdXY /mnt/boot

  • Mount the critical virtual filesystems. Run the following as a single command:

    for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done

  • Chroot into your normal system device:

    sudo chroot /mnt

At this point the / system partition is remapped to the CF drive. Anything installed or any changes to system configuration files will be made to the CF drive.

Step 3: Install & Configure

  • Install openssh-server

    sudo apt update sudo apt install openssh-server

The ssh server is installed. If you want to make some changes to the ssh server configuration, now is the time. However, be very careful as you may not be able to test the ssh server in this chroot environment. As a result, once the CF is in the embeded system, ssh may not work. The configuration file is located in /etc/ssh/sshd_config. The default config is reasonably secure. It does not allow the user root to login with password. If you plan to ssh as root then you have to either enable password based login for root or use private-public key pair based login. See How to set up passwordless SSH access for root user for more.

  • Exit chroot: CTRL-D on keyboard


I have not tested this method. If this does not work or there is any problem with the steps, let me know in a comment. I will try to fix the answer.

This answer is inspired by the method to install grub via chroot.

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.