I'm a little confuse regarding how one launches tmux. When I launch my terminal (current gnome-terminal), I would like to have tmux up and running.

I'm currently doing this by calling "tmux" in my .zshenv (kind of like .bashrc in bash). This does in fact launch tmux, but has some annoying side effects. First, hitting Ctrl-D to exit the shell, only kills tmux, and leaves the tmux-less gnome-terminal still running. An additional Ctrl-D will kill that as well. Second, when ssh into a box with this setup, I get a second, nested instance of tmux. I don't want tmux to launch again when I ssh.

Is this the right approach, how should tmux be launched usually?

6 Answers 6


Launching anything from .zshenv is definitely the wrong approach. This file is executed by every instance of zsh, even when running a script. Use .zshrc for things that should be done in interactive shells, and .profile (or .zprofile, if you've set zsh as your login shell) for things that should be done when you log in.

If you want tmux in every terminal, start tmux directly under the terminal, e.g., gnome-terminal -e tmux (change your GUI launcher to pass these arguments). You can pass arguments even with -e (though be careful with quoting), e.g. gnome-termminal -e 'tmux -s ~/.alternate.tmux.conf'.

If you also want to start tmux when you log in over ssh, you'll have to launch it from your ~/.profile. Do this only if the parent process of the login shell is sshd:

parent_process_name=$(ps -o comm= -p $PPID`)
case ${parent_process_name##*/} in
  sshd) type tmux >/dev/null 2>/dev/null && exec tmux;;

Another approach to starting tmux over ssh would be to obtain a session name from the environment. That way you could attach to an existing session. The easiest way is to write a small script on the server side, e.g. ~/bin/tmux-login-session:

if tmux has-session -t "$1"; then
  exec tmux attach-session -t "$1"
  . ~/.profile
  exec tmux new-session -s "$1"

Then use an ssh command like the following:

ssh -t hostname.example.com bin/tmux-login-session SESSION_NAME
  • Hi, I don't want to launch tmux when I use ssh, but thank you for the interesting script. As far as using "gnome-terminal -e tmux" from another terminal (to test it), it seems to briefly open a new gnome-terminal, and then immediately close it.
    – oneself
    Oct 19, 2010 at 15:09
  • @user33084: That shouldn't happen. It might be due to using the wrong shell configuration file (e.g. all environment variables must be defined in ~/.profile, not .zshenv or .zshrc, or else they won't be available in circumstances such as this). What do you see if you run gnome-terminal -e 'sh -c "tmux; read line"'? Oct 19, 2010 at 19:46

Here is how one can set tmux to launch with gnome-terminal:

  1. Launch gnome-terminal
  2. Menu > Edit > Profile Preferences > Title and Command (Tab)
  3. Check Run a custom command instead of my shell
  4. Populate Custom command with tmux

These instruction work for me on Ubuntu 11.04. The equivalent should work for gnome-terminal for any flavor of Linux.

  • It will work, but it will loose the "open terminal on current folder" option. It will always open a new terminal in the home.
    – Alberto
    Mar 22, 2020 at 11:05
  • This worked for me. Also, "open terminal in folder" still works for me. Jul 10, 2020 at 15:57

Execute the following commands at the terminal to get tmux to run everytime you launch gnome-terminal:

gconftool --type string --set /apps/gnome-terminal/profiles/Default/custom_command "tmux"
gconftool --type bool --set /apps/gnome-terminal/profiles/Default/use_custom_command "true"

These set of commands make gnome-terminal to launch tmux at terminal start.

  • This will result in gnome-terminal quiting when you quit tmux.
  • It will not interfere with ssh or login in anyway as it is a gnome-terminal setting.
  • Also, you can use all the shortcuts of gnome-terminal you have pinned on the desktop and launch it from the command line with tmux running, so you wont need to create a custom shortcut for this behaviour.

Ctrl+D exits the current shell, it doesn't exit your terminal emulator (unless your current shell is the first process started inside the terminal emulator). If you want to exit gnome-terminal, you can use Alt+F4 or Shift+Ctrl+Q.


In options for Terminal add this as the custom command - bash -c 'tmux attach || tmux new'

This will attempt to attach to any existing tmux session. If none exist it will start a new session and attach to it.


I've configured my ~/.bashrc such that it will automatically launch Tmux and attempt to connect to a session called 'main', or create it if it doesn't exist. I find this works for me:

if command -v tmux>/dev/null; then
    [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && tmux new-session -A -s main

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .