32

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
  • 614
  • 1
  • 8
  • 16

3 Answers3

49

You could use:

$ sudo ufw --force enable
Everaldo Canuto
  • 591
  • 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
  • 1
    This should be the correct answer. – Deckard Sep 15 '22 at 06:58
30

How about:

$ echo "y" | sudo ufw enable
EEAA
  • 109,363
  • 18
  • 175
  • 245
10

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

yes | sudo ufw enable
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89