Accepted publickey or Accepted password line in /var/log/auth.log, but there is no corresponding shell session. No command history, no session opened for user followed by actual activity, no entry in wtmp that lasts more than a second. The user authenticated, did nothing visible, and the connection sat there — sometimes for hours. This is one of the clearest signs of SSH port-forwarding abuse, and it is surprisingly common on internet-facing servers.
What SSH Port Forwarding Looks Like From the Server Side
-L), remote/reverse (-R), and dynamic SOCKS (-D). All three let an authenticated user route TCP traffic through your server without ever requesting a shell. The client connects, authenticates, sets up a tunnel, and the connection stays open as a pipe.
From auth.log, this looks almost identical to a normal login:
TEXT
# Illustrative auth.log entries — forwarding-only session
Jun 15 04:12:33 host sshd[28410]: Accepted publickey for deploy from 198.51.100.44 port 49221 ssh2: RSA SHA256:xxxxxx
Jun 15 04:12:33 host sshd[28410]: pam_unix(sshd:session): session opened for user deploy(uid=1001) by (uid=0)
Jun 15 10:45:01 host sshd[28410]: pam_unix(sshd:session): session closed for user deploy.bash_history. If you check last or utmp, you might see the session, but it looks like someone logged in and sat idle. The difference: they were not idle. They were proxying traffic.
An attacker with a compromised key or credential can use your server as a SOCKS proxy to hide their origin, pivot into your internal network, or expose an internal service (like a database on 127.0.0.1:3306) to the outside world — all without triggering command-level logging.
Step 1: Confirm Forwarding by Checking Active Connections
sshd), then inspect its network connections:
BASH
# Replace 28410 with the actual sshd child PID from auth.log
ss -tnp | grep 28410ESTABLISHED or LISTEN entries — connections to internal hosts, or a listening socket the user opened with -R.
Look for patterns like:
- Connections from the sshd child process to
127.0.0.1:3306,127.0.0.1:6379, or other local services. This means local forwarding (-L) is in use — the attacker is reaching services bound to localhost through your server. - A
LISTENsocket owned by the sshd child on an unexpected port. This means reverse forwarding (-R) — the attacker exposed something through your server, or opened a port for inbound connections. - Multiple outbound connections to various external IPs. This suggests dynamic forwarding (
-D) being used as a SOCKS proxy.
Step 2: Increase sshd Log Verbosity
LogLevel INFO) does not tell you whether a session requested forwarding. Bumping it to VERBOSE adds useful detail, including when port forwarding channels are opened.
In /etc/ssh/sshd_config:
TEXT
LogLevel VERBOSEsystemctl reload sshd preserves existing sessions), new connections will log more detail. With VERBOSE, you will typically see log lines when a forwarding channel is requested, including the target address and port.
Some administrators go further and set LogLevel DEBUG, but this generates a large volume of output and can include sensitive information. VERBOSE is usually enough to distinguish a forwarding session from an interactive one.
If you want even more granular auditing without flooding auth.log, consider enabling the ForceCommand directive for specific users or groups to log session types — but that changes behavior, so test it first.
Important before changing sshd_config: always keep an existing SSH session open while you test. A syntax error in the config will not kill your current connection, but it will prevent new ones. This is covered in more detail in Restarting sshd Won't Drop Your Session, but a Bad Config Locks Out the Next Login.
Step 3: Check for Key-Based Access Without Command Restrictions
authorized_keys file for that user. A well-configured key entry can restrict what the key is allowed to do:
TEXT
no-port-forwarding,no-X11-forwarding,no-agent-forwarding,command="/usr/local/bin/backup-only.sh" ssh-rsa AAAA...ssh-rsa AAAA... — then anyone with the private key can open forwarding channels, request a shell, or both. This is the default, and it is the root cause in many forwarding-abuse cases: a deploy key or automated-task key that was never locked down.
Check every key in the file. Pay attention to keys you do not recognize, keys without comments (the trailing user@host part), and keys that were added long ago for a purpose nobody remembers.
Step 4: Disable Forwarding Where It Is Not Needed
/etc/ssh/sshd_config:
TEXT
# Global default: disable all forwarding
AllowTcpForwarding no
AllowStreamLocalForwarding no
GatewayPorts no
# Re-enable only for users who actually need it
Match User tunneluser
AllowTcpForwarding yesAllowStreamLocalForwarding controls Unix domain socket forwarding — a less common but equally dangerous vector. GatewayPorts no prevents remote forwarding from binding to 0.0.0.0 (making it reachable from outside the server).
After changing the config, reload sshd and test with a legitimate connection to make sure you did not break anything.
Step 5: Correlate With Other Logs
- Web server logs or application logs might show requests originating from
127.0.0.1that do not match normal application behavior. If someone forwarded port 80 or an admin panel through SSH, the application sees local connections. - Database slow query logs or general logs might show connections from localhost at odd hours.
- Firewall logs (if you log dropped packets) might show the sshd process attempting outbound connections to destinations your server normally never contacts.
last -f /var/log/wtmpshows login sessions. A session that lasted hours with no corresponding shell activity in.bash_historyis worth investigating.
What to Do When You Find Active Abuse
- Kill the specific sshd child process for that session. Find the PID from auth.log or
ps aux | grep sshd, thenkill <PID>. This terminates the tunnel immediately. - Remove or restrict the compromised key from
authorized_keys. If password auth was used, change the password and consider disabling password auth entirely (PasswordAuthentication no). - Block the source IP at the firewall level if it is clearly malicious.
- Audit what was accessed through the tunnel. Check application and database logs for the time window the session was open.
- Apply the
AllowTcpForwarding norestriction as described above to prevent recurrence.
