I use a tiny .bashrc tweak for Proxmox SSH session monitoring. It runs when I SSH into a Proxmox host and reminds me if I left a screen or tmux session detached. The snippet is simple Bash scripting. It helps with SSH management and stops me leaving sessions running on the hypervisor. Below I show exact lines to drop into your .bashrc, notes on tmux alternatives, and a few troubleshooting tips.
Drop this into ~/.bashrc on the Proxmox host. It only runs for interactive SSH shells, so it won’t interfere with scp or non-interactive jobs.
bash
Proxmox SSH session monitoring
if [ -n “$SSHCONNECTION” ] && [ -t 1 ]; then
# check GNU Screen
screenout=$(screen -ls 2>/dev/null | grep -E ‘Detached|Attached’ || true)
if [ -n “$screenout” ]; then
echo “Reminder: screen sessions present:”
echo “$screenout”
fi
# check tmux
if command -v tmux >/dev/null 2>&1; then
tmuxout=$(tmux ls 2>/dev/null || true)
if [ -n “$tmuxout” ]; then
echo “Reminder: tmux sessions present:”
echo “$tmux_out”
fi
fi
fi
This code does three things. It detects an SSH session via $SSH_CONNECTION. It checks for screen sessions with screen -ls and filters for Attached or Detached. It checks tmux with tmux ls only if tmux is installed. The checks are quiet on error, so the prompt stays clean if no sessions exist. I keep the output short so it reads well over slow SSH links.
If you want a sharper reminder, use counts and thresholds. Replace the echo block with a one-liner that only warns when detached sessions exist:
bash
detachedcount=$(screen -ls 2>/dev/null | grep -c ‘Detached’ || echo 0)
if [ “$detachedcount” -gt 0 ]; then
echo “You have $detached_count detached screen session(s). Attach or kill them.”
fi
For tmux, parse the tmux ls output for sessions that are not attached. Tmux does not label sessions as Attached/Detached the same way, so a practical check is to count sessions and compare to tmux list-clients if you need per-session attachment details.
A few Proxmox tips from using this on several hypervisors. Run these checks only for interactive shells to avoid noise in automation. Keep the logic in .bashrc, not .profile, because Proxmox shells are interactive by default. If you prefer a dedicated script, point to it from .bashrc. If you use SSH multiplexing or jump hosts, the $SSH_CONNECTION test still works for the final hop. Use tty -s or [ -t 1 ] to ensure the terminal is present.
Troubleshooting is straightforward. If nothing shows up, test the commands manually: screen -ls and tmux ls. If tmux ls returns “no server running”, there are no sessions. If the checks print unexpected errors, add 2>/dev/null to silence them. If the reminder fires on local logins, check that $SSH_CONNECTION is empty for local sessions and only non-empty for SSH. Lastly, keep the messages short and actionable so they catch attention without blocking quick fixes.
These small changes save me time and messy cleanup on Proxmox. The approach mixes simple Bash scripting with plain SSH management checks. It works with screen and with tmux alternatives. Add the snippet, test the checks manually, then let it remind you when you next SSH in.







