Adding ufw rules during a preseeded installation
Solution 1:
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
The workaround will add a custom rc.local
script using preseed/late_command
which will:
-
Make a backup of the original
rc.local
asrc.local.orig
(usingmv
) -
Then new
rc.local
is created -- which is a script that will be executed on the first boot up of the system -
The new script will:
- Enable SSH access using
ufw
- Restore the original
rc.local
(by movingrc.local.orig
torc.local
, deleting itself) - Test if the original
rc.local
is executable and run it - Exit successfully
- Enable SSH access using