CH-J Server Managerserver management over SSH
Menu
All guides and articles →

How to manage several SSH servers at once

Keep several servers organised with SSH aliases and side-by-side terminals, and avoid running a command on the wrong one.

Give every server a clear name

A consistent alias saves time and reduces mistakes. In ~/.ssh/config, keep the address, user, port and key of each server under one name, and put the role and environment into that name, so production is obvious at a glance. Options you do not set for a specific host fall through to the Host * block.

Host prod-web-1
    HostName 203.0.113.10
    User admin
    IdentityFile ~/.ssh/id_ed25519_prod
    IdentitiesOnly yes

Host test-web-1
    HostName 203.0.113.20
    User admin

Avoid the wrong server

Working on several servers makes it easy to type a command in the wrong window. Show the host name in the prompt, use a different prompt color on production and check where you are before anything destructive. Save the most dangerous steps for a moment when only one terminal is open.

hostname -f; whoami; pwd

Keep long work alive

A dropped connection normally ends the shell and the commands running in it. Run long jobs inside tmux or screen on the server, so they continue and you can reconnect to them. Client keepalive detects a dead connection sooner, but it does not keep the job running by itself.

tmux new -s upgrade
tmux attach -t upgrade

Know which servers respond

Before starting work across several servers, check that their SSH ports respond. A closed port does not always mean a server is down: the service may have stopped, or a firewall may be blocking your network.

for host in prod-web-1 test-web-1; do
    ssh -o ConnectTimeout=5 "$host" 'hostname; uptime' || echo "$host: no connection"
done

Several servers in CH-J Server Manager

Server profiles are stored in a local encrypted vault, and several SSH sessions can be open at once. In Alpha 0.1.1 two terminals sit side by side or stacked, on one server or two, and hiding a terminal does not end its session. Modules use a single connection automatically and ask when several are open, so a module never moves to another server by itself. Locking the vault disconnects SSH sessions, so finish running work first or keep it in tmux.

Availability at a glance

In Alpha 0.1.1 the availability monitor checks saved servers in the background with a TCP connection to the SSH port, by default every 12 seconds, without logging in. Offline then means the SSH port cannot be reached from your network; the server itself may still be running.

Detailed documentation

OpenSSH: ssh_config →

Biometric unlock and security →