• Security
  • Story

Port knocking hides your SSH port, but your keys still do the locking

My take: Port knocking hides the SSH door from scanners, it does not lock it. Worth a layer on a VPS, never a reason to drop your keys.

What to know

  • Port knocking hides a service behind a closed firewall: the port stays shut until a client hits a secret sequence of other ports, in order. knockd, by Judd Vinet, watches for that sequence on a network interface, then runs the command you wrote, usually a firewall rule that opens port 22 (SSH) to the knocker's address only. A second command can close it again after a delay you set (cmd_timeout). GPL-2.0 license, version 0.8 released on April 24, 2021, packaged in Debian as knockd.
  • Its man page says knockd listens on eth0 by default. If your server's network card has another name (ip link shows it), set it with -i or the Interface option, or knockd hears nothing and the door stays shut, for you too.
  • The sequence crosses the network in clear: anyone watching your traffic can replay it. knockd can use one-time sequences, crossed off a list as they are used. fwknop goes further with a single encrypted, authenticated packet that cannot be replayed (version 2.6.11, February 7, 2024).
knock -v server.example.com 7000 8000 9000
ssh you@server.example.com

Spotted on @lelabdepatrice's reel, in French.

What changes

For a VPS you reach over SSH, your login port drops out of the scans that sweep every address on the internet. It hides the door; your SSH keys remain the lock, so keep them. Before you close port 22 to everyone, test the knock from a second session and check that your host's rescue console works: one typo in the config and you are locked out.

Source: Judd Vinet, “knock: a port-knocking daemon”, April 24, 2021

Drafted with Claude, Anthropic's AI, from my take. Reviewed and owned by me.

Up next