6

I want to set up ufw on remote machine while connecting by SSH. I type

ufw reset
ufw default deny incoming
ufw default allow outgoing

ufw allow ssh
ufw allow 22
ufw enable

And after that it immediately blocks ssh connection, and does not accept new ones. The only thing I can do is to reset the server. Did I miss something?

EDIT 1: OF cause I do have ssh configured. I am accessing server by SSH. This means it is configured and that I have connection to the server until I run ufw enable

0
2

I am currently having the same issue. For now, I did this as a workaround.

ufw default allow incoming
ufw deny 1:21/tcp
ufw deny 23:65535/tcp
4
  • May I ask if your problematic machine is ARM or other non-x86? – Barafu Albino Dec 10 '16 at 13:25
  • I am a Windows person so unfortunately I do know how to check it. However, it is a BareMetal instance with 11.99€ price here – Mehmet Ataş Dec 10 '16 at 13:30
  • Try typing file /bin/bash. For my desktop it says ELF 64-bit LSB executable, x86-64, for my ARM server it is ELF 32-bit LSB executable, ARM, EABI5 version 1 – Barafu Albino Dec 11 '16 at 22:37
  • 1
    Mine says ELF 64-bit LSB executable, x86-64. – Mehmet Ataş Dec 12 '16 at 6:06
0

Doing this on a fresh install worked fine for me, even after a reboot, on Ubuntu 16.04.2

ufw enable
ufw allow ssh
ufw allow 22
ufw enable
0

I solved using expect command:

apt install expect -y

if [ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
  expect -c "
    set timeout 3
    spawn ufw enable

    expect \"Command may disrupt existing ssh connections\"
    send -- \"y\r\"
    expect eof
"
else
  ufw enable
fi

apt purge expect -y

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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