Ubuntu – How to run ‘ufw’ without interactive mode

ufw

I want to run ufw Uncomplicated Firewall from python script but it usually runs in interactive mode. Example:

subprocess.check_output(["ufw", "enable"])

Has the following output:

'Command may disrupt existing ssh connections. Proceed with operation (y|n)? Aborted'

Is there a way to run ufw without interactive mode?

Best Answer

Use

ufw --force enable

You may want to have a look at the Gufw source code, it's written in Python. At least in Ubuntu 14.10 the calls to ufw are in the file gufw/model/ufw_backend.py.

You can download the source code using

apt-get source gufw