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?

  • 3
    Try ufw --force enable – Panther Apr 20 '15 at 18:30
up vote 23 down vote accepted


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
  • Example: sudo ufw --force-enable reset – Underverse Jun 17 '17 at 12:36

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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