What is port knocking?
Leaving a remote-access port like SSH open to the internet at all times makes it an easy target for automated port scans and brute-force attacks. Port knocking keeps that port completely closed by default β invisible to any scan β and only has the firewall open it once a specific sequence of connection attempts ('knocks') to a set of ports arrives in the right order.
How it works: a specific sequence of attempts
A client might attempt short connections to, say, ports 7000, 8000, then 9000 in that exact order; a knock daemon on the server watches the firewall logs for that pattern and, once it matches, temporarily opens the real target port (e.g. SSH's 22) for just that client's IP.
Benefit: invisible to port scans
A normal firewall's 'this port is closed' response still reveals that a server is alive and listening; a port-knocking server gives an attacker who doesn't know the sequence no way to tell that any port could ever be opened at all, which removes it from most automated scanners' target lists.
Limitation: security through obscurity
Port knocking isn't strong cryptographic authentication β it relies on secrecy of the sequence itself, which can be defeated if the knock is intercepted on an unencrypted network and replayed, or in theory brute-forced across the full range of ports and orderings. It's best understood as a supplementary layer added in front of real authentication like SSH keys or strong passwords, not a replacement for them.
A more advanced approach: SPA (Single Packet Authorization)
Instead of a sequence of multiple connection attempts, SPA sends a single encrypted packet containing authorization data β the server decrypts and validates it before opening the port. Because the packet's contents differ every time, unlike classic port knocking it isn't vulnerable to a captured packet simply being replayed. fwknop is a well-known open-source SPA implementation.
Real-world use cases
Mainly adopted selectively by administrators of personal servers or small infrastructure who want an extra layer of concealment on SSH or admin ports exposed to the internet. It's impractical for always-on public services like a web server, and the more complex the setup, the more inconvenient it can become even for the admin's own remote access β a tradeoff worth weighing before adopting it.