All ArticlesSecurity2026-11-12T12:28:24+08:00

SSH Login Succeeded but No Command in auth.log? Check for Port Forwarding Abuse

You see successful SSH authentications in auth.log but no corresponding shell commands or session activity, and you are unsure if the access is malicious. After reading, you will know how to identify SSH tunnel and port-forwarding abuse by reading log entries, sshd debug output, and netstat connections.

You see a clean 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

SSH supports three types of forwarding: local (-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:

# 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

Six hours between open and close. No commands logged anywhere. No entries in .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

While a suspicious session is still open, check what that sshd process is actually doing. Find the PID from auth.log (the number in brackets after sshd), then inspect its network connections:

# Replace 28410 with the actual sshd child PID from auth.log
ss -tnp | grep 28410

If the session is a plain interactive login, you will typically see only the single inbound SSH connection on port 22 (or whatever port sshd listens on). If forwarding is active, you will see additional ESTABLISHED 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 LISTEN socket 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.

If the session already closed, you will not see these connections anymore, but you can still correlate timestamps. Check whether any unusual outbound traffic or internal service access happened during the window that session was open.

Step 2: Increase sshd Log Verbosity

Default sshd logging (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:

LogLevel VERBOSE

After reloading sshd (not restarting — systemctl 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

If the login used a public key, check the authorized_keys file for that user. A well-configured key entry can restrict what the key is allowed to do:

no-port-forwarding,no-X11-forwarding,no-agent-forwarding,command="/usr/local/bin/backup-only.sh" ssh-rsa AAAA...

If the key entry has none of these restrictions — just a bare 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

If a user account does not need port forwarding, disable it explicitly. In /etc/ssh/sshd_config:

# Global default: disable all forwarding
AllowTcpForwarding no
AllowStreamLocalForwarding no
GatewayPorts no

# Re-enable only for users who actually need it
Match User tunneluser
    AllowTcpForwarding yes

This is the single most effective mitigation. Even if an attacker compromises a key, they cannot set up tunnels if the server refuses forwarding for that user.

AllowStreamLocalForwarding 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

Forwarding abuse often leaves traces outside auth.log:

  • Web server logs or application logs might show requests originating from 127.0.0.1 that 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/wtmp shows login sessions. A session that lasted hours with no corresponding shell activity in .bash_history is worth investigating.

If you are dealing with brute-force attempts that precede the successful login, checking auth.log for the volume of failed attempts from the same IP is a good starting point. That pattern is covered in VPS Load Spikes With No Site Traffic? Check auth.log for SSH Brute Force.

What to Do When You Find Active Abuse

If you confirm an active forwarding session that should not exist:

  1. Kill the specific sshd child process for that session. Find the PID from auth.log or ps aux | grep sshd, then kill <PID>. This terminates the tunnel immediately.
  2. 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).
  3. Block the source IP at the firewall level if it is clearly malicious.
  4. Audit what was accessed through the tunnel. Check application and database logs for the time window the session was open.
  5. Apply the AllowTcpForwarding no restriction as described above to prevent recurrence.

The gap between "authenticated successfully" and "did something malicious" is where forwarding abuse lives. Standard auth.log at default verbosity will not flag it for you. The combination of bumping LogLevel, restricting forwarding per user, and locking down authorized_keys entries closes that gap. If a session authenticates and then does nothing visible, treat it as suspicious until you can prove otherwise.