Disconnect Dovecot Sessions Safely with doveadm kick
Use doveadm kick to boot a stuck, compromised or misbehaving client off your Dovecot server without restarting the whole service. You will match sessions by login name, source IP address, network range, or a user and network together. Allow about 10 minutes for a careful one-off, preview included.
The route
Jump straight to the step you need, or tick off Done means at the end.
This guide follows the locally installed Dovecot 2.3.21 package on Ubuntu.
Before you start
- What you need: the
dovecot-corepackage, a shell on the Dovecot server, and administrative access to the Dovecot control socket. Run as a user that can reach it, commonly root or a suitably privileged service administrator. - Placeholders: the examples use documentation addresses and names. Replace them with real values only after checking the current sessions.
- What it does not do: it does not delete mail, disable an account, or block an address.
Warning
doveadm kick is service-disrupting. Matching clients are disconnected and may reconnect immediately. Treat a broad user pattern or network range as an outage-sized action.
1. Check the installed command and current sessions
The reference system reports version 2.3.21. Confirm the package version on your host, then list sessions before choosing a mask.
dpkg-query -W -f='${Version}\n' dovecot-core
sudo doveadm who -1
Expected output is a table with fields such as username, proto, pid and ip. If doveadm who cannot connect to the socket, stop here and fix the service or permissions. Do not guess a socket path while preparing a disconnect.
Checkpoint
Write down the exact login name and source address you intend to match. A displayed address is the client address known to Dovecot, which may be a proxy rather than the user's original address.
2. Preview a user's sessions
Use doveadm who with a user mask to see the likely target. In a shell, quote wildcard masks so the shell does not expand them against local filenames.
sudo doveadm who -1 '[email protected]'
sudo doveadm who -1 'jane*'
The first command targets one login name. The second is broader and can match any login name beginning with jane. who is only a preview and disconnects nothing.
3. Disconnect by login name
When the preview shows the intended accounts, pass the same mask to kick.
sudo doveadm kick '[email protected]'
For a wildcard example, ba? matches three-character login names beginning with ba, such as bar and baz. When matching connections are removed, the command prints a list headed by kicked connections from the following users:. An empty or non-matching result is not evidence that every session is gone, so repeat the preview.
Warning
'*' is a valid broad user mask and can disconnect every matching Dovecot session. Do not use it as a quick way to test the command.
4. Disconnect by address or network
Use an individual address for one observed client, or CIDR notation for a network. The command accepts both IPv4 and IPv6 addresses.
sudo doveadm who -1 '192.0.2.53'
sudo doveadm kick '192.0.2.53'
sudo doveadm who -1 '192.0.2.0/24'
sudo doveadm kick '192.0.2.0/24'
Warning
The network form disconnects all users connected from that range. A /24 covers many addresses, not just the one in your preview, so check the range carefully. Quote the argument as shown in case your shell or a wrapper treats the slash specially.
5. Narrow the action to a user and network
The safest useful form often combines a login mask with an address range. It disconnects only sessions that satisfy both conditions.
sudo doveadm who -1 'foo'
sudo doveadm kick 'foo' '192.0.2.0/24'
sudo doveadm who -1 'foo'
Checkpoint
After the kick, sessions for foo from the documentation range should be gone, while a session for foo from another address can remain. The command can print the user's name even when several matching connections existed.
6. Handle the force option and alternate socket
Normally, Dovecot avoids a disconnect when multiple users from different networks share one process. The -f option enforces the disconnect in the special configuration the manpage describes: for example, an IMAP service with client_limit set to 1+n, service_count set to 0, and several users in one process.
sudo doveadm kick -f 'foo' '192.0.2.0/24'
Tip
Use -f only when you understand that shared-process situation. It is not a general repair switch for a failed socket or a permission error.
The default control socket is /run/dovecot/anvil. If the configured base_dir puts it elsewhere, supply an absolute path:
sudo doveadm kick -a '/run/dovecot/anvil' 'foo'
Use the actual path from the running configuration. An alternative socket path does not bypass permissions or make an incompatible Dovecot instance safe to control.
7. Verify and recover
Run the same who query after every kick. If a session is still listed, check these:
- Exact match. The username and address were copied exactly.
- Proxy in the way. A proxy has not changed the visible address.
- Right instance. You used the intended Dovecot instance.
Add -v for progress output or -D for debug messages when investigating a controlled failure. Avoid leaving debug output in shared logs if it contains operational details.
sudo doveadm who -1 'foo'
sudo doveadm who -1 '192.0.2.0/24'
Recovery
There is no undo command, because a kick only ends the connections. Affected users recover by reconnecting, subject to your normal authentication and service policy. If clients reconnect immediately, use the preview to tell a successful kick from an ongoing client or network problem.
Done means
- Version confirmed. You checked the installed Dovecot version and could run
doveadm who. - Previewed first. You looked at the exact user, address or network before disconnecting it.
- Masks quoted. You quoted them and treated wildcard and CIDR matches as broad actions.
- Result verified. You checked the post-kick session list, and know recovery means reconnecting, not undoing the command.