Remote session management
When running long jobs remotely (training, builds, data processing), you need to protect against network disconnections. Without session management, a dropped connection kills your running process.
tmux basics
Section titled “tmux basics”tmux keeps your session alive on the server, even if your connection drops.
# Start a new sessiontmux
# Detach from session (keeps it running)Ctrl+b d
# List existing sessionstmux ls
# Reattach to sessiontmux attach
# Reattach to a specific session by nametmux attach -t session_nameFor a full list of keybindings, see the tmux cheat sheet.
Eternal Terminal (optional)
Section titled “Eternal Terminal (optional)”Eternal Terminal (ET) automatically reconnects when your network drops, without losing your session state. It’s an alternative to SSH that handles reconnection gracefully.
Install the client on your local machine:
sudo add-apt-repository -y ppa:jgmath2000/etsudo apt-get updatesudo apt-get install -y etConnect with agent forwarding:
et -f hostnameET uses your SSH config for hostname/user resolution. The remote server must have ET installed and port 2022 open.
SSH agent forwarding with tmux
Section titled “SSH agent forwarding with tmux”When using SSH agent forwarding (ssh -A or et -f) with tmux, there’s a common problem: after reconnecting,
the SSH_AUTH_SOCK environment variable in your tmux session points to a stale socket path.
This breaks git and other SSH operations.
The solution is to maintain a stable symlink to the current socket. Run this on the remote server to add it to your bashrc:
cat >> ~/.bashrc << 'EOF'
# Stable SSH agent socket path for tmux sessionsif [ -n "$SSH_AUTH_SOCK" ] && [ "$SSH_AUTH_SOCK" != "$HOME/.ssh/ssh_auth_sock" ]; then mkdir -p ~/.ssh ln -sf "$SSH_AUTH_SOCK" "$HOME/.ssh/ssh_auth_sock" export SSH_AUTH_SOCK="$HOME/.ssh/ssh_auth_sock"fiEOFAfter adding this, new login shells will update the symlink and point to it. Your tmux sessions will use the stable path that always resolves to the current socket.