Terminal Desktop with Tmux

I put together a little article on setting up a desktop interface using Tmux. It is like a tiling window manager but in the terminal. So a terminal tiling manger? Tiling Terminal Manager? Whatever you want to call it. It allows for you to “detach” from your terminal session and come back to it just as you left it. I took a lot of information I found out there and boiled it down for the Tmux noob like myself.


I’m a big fan of tmux and use it on all the servers I manage. Being able to pick up after being disconnected it hugely helpful, especially for long-running processes. I have it set so that when I connect via ssh, a tmux session is either resumed or created if one doesn’t exist. You can add this to your .bashrc file.

1 Like

That is cool. Can you show me how you add it to your .bashrc file? Like the syntax and such? I am looking into creating a tmux template so that when I reboot my server, it creates the tmux session automatically. I just started looking at it. I haven’t ACTUALLY got anywhere with it. :slight_smile:

This is what I use. It’s for ssh connections. I’m not sure how you would launch it at start, probably a script I’d guess.

Server-side configuration:

To automatically start tmux on your remote server when ordinarily logging in via SSH (and only SSH), edit the ~/.bashrc of your user or root (or both) on the remote server accordingly:

if [[ -n "$PS1" ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_CONNECTION" ]]; then
  tmux attach-session -t ssh_tmux || tmux new-session -s ssh_tmux

This command creates a tmux session called ssh_tmux if none exists, or reattaches to a already existing session with that name. In case your connection dropped or when you forgot a session weeks ago, every SSH login automatically brings you back to the tmux-ssh session you left behind.

Connect from your client:

Nothing special, just ssh user@hostname.

That is cool. I like it. I was looking at scripting how tmux starts so that I can set my panes and windows to my liking. Now, however, I am thinking that there is a lot more I can do then just start Tmux. Hmmm…

You might want to look into tmux-resurrect. Additionally, tmux-continuum adds autosave, -start, and -restore features.

1 Like

That is fantastic information. I will certainly play with those when the time comes.