Shared server guidance · Question & answer

How do I keep a Linux terminal session after SSH disconnects?

tmux runs terminal sessions on the Linux server so you can detach and reconnect after a network interruption. It must be installed and allowed on that server. It does not make a task restart automatically after a reboot.

IntermediateWindows 11 with Microsoft OpenSSH Client; Windows PowerShell 5.1 or PowerShell 7 as labelledLinux VPS and dedicated servers where a remote Linux command is shown
Go to the answer

Before you start

  • tmux is installed on the Linux server.
  • The task is authorised to continue while you are disconnected.

Instructions

1. Check for an existing session

Run this after you have authenticated to Linux, not in local Windows.

Remote Linux shell
tmux list-sessions

An existing named session can be reattached. A message that no server is running simply means there are no current tmux sessions for this context.

2. Create a clearly named session

Choose a distinct session name and run the intended authorised task inside it.

Remote Linux shell
tmux new-session -s maintenance

This creates a remote session named maintenance. To detach, press Ctrl+B, release the keys, then press D.

3. Reconnect to the same session

After a later SSH login, attach to the existing session rather than starting a duplicate task.

Remote Linux shell
tmux attach-session -t maintenance

The task state appears where it was left, provided the session and server have remained alive.

Check the result

  • tmux list-sessions shows the intended named session.
  • After detaching and reconnecting, the original session is available.

Troubleshooting

tmux is not installed
Use the distribution’s approved package process or the application’s existing service mechanism.
The session vanished after a reboot
tmux is not a reboot persistence or recovery service. Check the task outcome before running it again.

Official references

Use the documentation for your installed version when a flag, service name or platform feature differs.