27

I'm trying to automate the setup of UFW on an Ubuntu 16.04 instance. However when I type:

sudo ufw enable

I get prompted to enter yes or no, is there a way to feed it yes or set it automatically to start without getting stuck with a prompt?

Adron
  • 564
  • 1
  • 7
  • 16

3 Answers3

38

You could use:

$ sudo ufw --force enable
Everaldo Canuto
  • 481
  • 4
  • 2
  • 2
    I had to check the manpage to be sure `--force` doesn't do anything unexpected: "By default, ufw will prompt when enabling the firewall while running under ssh. This can be disabled by using 'ufw --force enable'." – Nickolay Jan 13 '22 at 04:53
  • This should be the correct answer. – Deckard Sep 15 '22 at 06:58
27

How about:

$ echo "y" | sudo ufw enable
EEAA
  • 108,414
  • 18
  • 172
  • 242
10

yes allows you to answer all questions from a program with y.

yes | sudo ufw enable
Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79