Skip to content
The Chat Archive
Claudeclaude-opus-4-20250514-thinking-16k· Anthropic LMArena Human Preference 140K

how to keep a ssh connection permanent

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-opus-4-20250514’s answer.
  1. User

    how to keep a ssh connection permanent

  2. Assistant

    There are several ways to keep SSH connections persistent and prevent them from dropping:

    SSH Configuration Options

    Add these settings to your SSH client configuration (~/.ssh/config):

    Host *
        ServerAliveInterval 60
        ServerAliveCountMax 3
        TCPKeepAlive yes
    

    Or use them directly in your SSH command:

    ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=3 user@host
    

    These settings send keepalive packets every 60 seconds to prevent the connection from timing out.

    Terminal Multiplexers

    Screen or tmux let you maintain persistent sessions that survive disconnections:

    # Start a new screen session
    screen -S mysession
    
    # Detach with Ctrl+A, then D
    # Reattach later with:
    screen -r mysession
    

    For tmux:

    # Start new session
    tmux new -s mysession
    
    # Detach with Ctrl+B, then D
    # Reattach with:
    tmux attach -t mysession
    

    Autossh

    Autossh automatically restarts SSH connections when they drop:

    # Install autossh
    sudo apt-get install autossh  # Debian/Ubuntu
    brew install autossh           # macOS
    
    # Use it like regular SSH
    autossh -M 0 user@host
    

    Mosh (Mobile Shell)

    Mosh is designed for unreliable connections and roaming:

    # Install on both client and server
    sudo apt-get install mosh
    
    # Connect
    mosh user@host
    

    SSH Multiplexing

    Reuse a single connection for multiple sessions by adding to ~/.ssh/config:

    Host *
        ControlMaster auto
        ControlPath ~/.ssh/sockets/%r@%h-%p
        ControlPersist 600
    

    The best approach depends on your specific needs - use keepalive settings for simple timeout prevention, terminal multiplexers for persistent work sessions, or autossh/mosh for unreliable connections.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.