What is Tmux?
Tmux is a modern terminal multiplexer – a tool that lets you create and manage multiple virtual terminals within a single SSH session. This means you can start, for example, a game server, detach from the session, and your server will keep running in the background. Tmux is a great alternative to the popular Screen tool, offering more features and a very convenient workflow.
Installing Tmux
Ubuntu / Debian:
sudo apt update
sudo apt install tmuxCentOS / Fedora:
yum check-update
yum update
sudo yum install tmuxIf you're logged in as root, you can skip sudo.
Basic Tmux Commands
Creating a new session
tmux- creates a new session and immediately opens a virtual terminal.tmux new -s name- creates a new session with a custom name, e.g.tmux new -s minecraft-server.
Detaching from a session
Leave the session running in the background:
PressCtrl + B, thenD.Close the session:
PressCtrl + B, thenX, and confirm by typingY.
Reattaching to an existing session
List your sessions:
tmux lsAttach to a session:
tmux a -t session_name
Closing all Tmux sessions
tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs killWorking with Windows and Panes
With Tmux, you can create multiple windows in a session and split each window into panes.
Most useful shortcuts (always start with Ctrl + B):
Sessions:
:new – new session
s – session list
$ – rename session
Windows:
c – new window
w – window list
n – next window
p – previous window
, – rename window
& – close window
Panes:
% – vertical split (left-right)
" – horizontal split (top-bottom)
o – switch between panes
q – show pane numbers
x – close pane
space – change pane layout
{ / } – move paneExample: Running a Minecraft Server in Tmux
Create a new session:
tmux new -s minecraft-serverEnter your server directory and start the server:
cd minecraft-serverjava -Xmx1024M -Xms1024M -jar minecraft_server.jar noguiDetach from the session:
Ctrl + B, thenD.
Your server will keep running in the background, even after you disconnect from SSH!
Summary
Tmux is a tool that makes server management much easier, especially if you run multiple tasks at once. If you have questions or want to learn more, feel free to leave a comment!
