14

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?

Samuel
  • 283

2 Answers2

38

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
0

Despite it's an old question, this might be helpful for others. It's possible to use --force option for deleting rules. for example:

# ufw --force delete 1

I wrote this code snippet to delete all 20 top rules:

# for i in `seq 20`; do ufw --force delete 1; done
mahyard
  • 103