I've been trying to automatically add UFW rules to allow SSH access during an installation of 16.04 while using a preseed file. However, none of the documented methods result in port 22 being open after the first boot.

Specifically, I've tried variations of the following lines:

ufw     ufw/enable      boolean true
ufw     ufw/allow_custom_ports  string 22/tcp
ufw     ufw/allow_known_ports  string 22/tcp
ufw     ufw/allow_known_ports   string  SSH

But none of them seemed to make a difference. Additionally, my attempts to add the rule in the post-install section failed as the iptables kernel module is not loaded, resulting in an error.

Is this possible to accomplish within the preseed file? Or should I just give up and enable the firewall on boot with a hack?

  • I don't see why this would be needed. Default install of Ubuntu has IPTables set to ACCEPT all inbound packets by default already. Is there some other element to your setup that we should know? Does your preseed include installing an SSH server to listen on the port? – user535733 Feb 6 '17 at 17:43

I have been trying to get this working for a while, too. Nothing seems to work. Until I finally gave up and I fixed it with a simple rc.local workaround:

d-i preseed/late_command string \
    mv /target/etc/rc.local /target/etc/rc.local.orig; \
    echo '#!/bin/sh -e' > /target/etc/rc.local; \
    echo '/usr/sbin/ufw allow ssh' >> /target/etc/rc.local; \
    echo 'mv -f /etc/rc.local.orig /etc/rc.local' >> /target/etc/rc.local; \
    echo 'test -x /etc/rc.local && /etc/rc.local' >> /target/etc/rc.local; \
    echo 'exit 0' >> /target/etc/rc.local; \
    chmod +x /target/etc/rc.local

Basically I made a custom rc.local script which executes ufw allow ssh on first start up, which then will destroy itself by renaming the original rc.local script back to the original place. This seems to work.

| improve this answer | |

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.