All Paths Lead to Tmux
Only people who are trying have a linux server will be interested in tmux.
And the only people who don’t know the difference between tmux and a terminal are people who don’t use linux which is 95% of the world (i made up this number but it’s close to what you find if you google it).
I’m in that 95%, slowly making the move to be part of the 5%
Scroll to the bottom if you want to know the difference, I went on a tangent.
Short story long, I had no interest in this topic until now.
That’s because… I just built a linux server last month.
I can’t describe how amazing it is now have my own server that’s always on.
It’s actually life changing.
The possibilities are endless, especially now that you can have AI do a lot of stuff for you.
If you’re a bit ADHD and very OCD like I am you might be interested in setting up a personal linux server to organize your life. You can read about it in this article.
Anyways, I just want to embrace that I’ve become a real nerd.
Connecting to the Server
Once you have your server up and running you actually don’t want to be anywhere near the server.
It’s just there humming along doing work for you.
You just have to send it commands and it’ll diligently keep working.
Now the problem becomes: how do you connect to it and send it commands.
The only real way is to SSH into the machine. You can read about how to basics of setting up SSH in this article.
Now that we know you have to SSH, there’s actually a lot of ways to do this.
The most basic is to use the built in terminal on your on your MacOS or the powershell on Windows. This is all you need to get started and set things up. This is what I used at first
Then I moved on to using iTerm2 because I wanted to open more windows and customize my view a little.
Next I tried VSCode Remote SSH extension which seemed to me like everything I needed until it kept disconnecting.
The Winner Is tmux with iTerm2
And now I’m back to using iTerm2 BUT with tmux!
At first I thought that tmux was another terminal client that I used and that it is an alternative to iTerm2.
But then I spent the last 2 hours learning how to use it and realize that I need to use them together.
Basically you need both. And simply, the setup is:
- Use a terminal like iTerm2 as the terminal interface
- Have tmux installed on your linux server as the software that allows you to have a persistent session to control multiple windows
You don’t need tmux on your local personal computer. Just install it on you linux server with sudo apt install tmux.
Here are the basic commands that you’ll need to get started
## ssh into your server
ssh your-server
## install tmux on your server
sudo apt install tmux
## check the tmux is installed
tmux -V # should print something like "tmux 3.3a"
## start a new tmux session
tmux new -s your-session name
## to detach Ctrl+b then D
## see all the tmux sessions
tmux ls
## attach to the most recent session or create a new session
## make sure that you're not already in a tmux session
tmux attach || tmux new -s your-session-name
## or use a shorthand to connect
tmux a
## attached to a specific session
tmux a -t index-of-session
## kill a specific session
tmux kill-session -t name-of-session
And here are the basic key bindings that you’ll need to navigate around
| Action | Keys |
|---|---|
| Detach (leave session running) | Ctrl+B then D |
| Split pane vertically | Ctrl+B then % |
| Split pane horizontally | Ctrl+B then " |
| Switch between panes | Ctrl+B then arrow keys |
| Create new window | Ctrl+B then C |
| Switch windows | Ctrl+B then 0-9 |
| Scroll up in pane | Ctrl+B then [ (then arrow keys, Q to exit) |
