rasen58
rasen58

Reputation: 5081

How to log out of SSH session without closing tmux

Is there a command I can use to log out of an SSH session where I have tmux running? Currently, if I want to leave tmux running, I either close the entire window of my ssh session without logging out, or I just let the SSH connection die after inactivity.

But I want to use a command to log out without closing the entire window. If I just type logout, then it closes my tmux session and still keeps me logged in to SSH. I then have to type logout again to close the SSH session. But I just want to type one command that disconnects SSH without closing tmux. Is this possible?

Upvotes: 23

Views: 20134

Answers (2)

Atharva Parulekar
Atharva Parulekar

Reputation: 561

First press CTRL+b the press d. This detaches your session. You then press CTRL+d to log out of ssh. Your detached session still keeps running on the server. You can attach it later by tmux attach-session -t 0 when you log on to server.

Upvotes: 46

Leo Adberg
Leo Adberg

Reputation: 342

You can set up a new screen that will continue running after you exit SSH. First, run screen -D -R over SSH to enter a new screen, then start up tmux. Feel free to just close the terminal window or exit the current screen with Ctrl-A or Ctrl-D. Now, you can always run screen -D -R again to go back into the screen you opened earlier.

EDIT: I'm silly, but the above might help someone who's not using tmux. Check the comments.

Upvotes: 6

Related Questions