Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like my default bash shell to go straight into tmux instead of my always having to type tmux every time.

share|improve this question
up vote 17 down vote accepted

This seems to work...


Simply add the following line of bash code to your .bashrc before your aliases; the code for other shells is very similar:

[[ $TERM != "screen" ]] && exec tmux
share|improve this answer
Please don't post answers that are just links to other pages; at least summarize what it says – Michael Mrozek Jul 20 '12 at 17:32
For me this also required [[ $- != *i* ]] && return to not being an infinite loop (from the same page) – Keith Smiley Apr 14 '13 at 1:45

@StarNamer's answer is generally accurate, though I typically include the following tests to make sure that tmux (1) exists on the system and (2) doesn't try to run within itself:

if command -v tmux>/dev/null; then
  [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && exec tmux
share|improve this answer
Nice, I have needed command before but didn't realize it existed. – Freedom_Ben Jun 21 '15 at 0:25
I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B edits my .bashrc. Vim can't open for some reason if the above is at the top of the bashrc. I've wrapped the middle line in another if statement, if [ ! -z "$PS1" ]; then...fi (checking that it's running in interactive mode) – Louis Maddox Aug 2 '15 at 20:03
this exec statement doesn't let you exit tmux without quitting the entire terminal! :| – Louis Maddox Aug 2 '15 at 20:43
@LouisMaddox: exec replaces the current process with a new one - in this case, it replaces the bash login shell with tmux, so when tmux exits then there is no other terminal to fall back to :) – Mark K Cowan Dec 8 '15 at 12:21

There is command chsh which changes login shell. Consult man chsh.

share|improve this answer
tmux is not a shell, it's a terminal multiplexer like GNU screen. Interestingly, it does support the -c option according to the man page, so it may work like a shell just enough to use it as your login shell, but I suspect it won't work properly in all situations, e.g. graphical logins via gdm/kdm. – Mikel Jul 20 '12 at 15:32
Although this is sensible and backed by the documentation, it seems to break direct command execution via SSH (something like ssh $some_server echo foo). – n.st May 11 '14 at 2:11
tmux as of at least 1.8 on Ubuntu adds itself to /etc/shells, so it is a valid login shell. – claytron Mar 26 '15 at 17:14

I'm successfully using

case $- in *i*)
    [ -z "$TMUX" ] && exec tmux

in my .zshrc. If you're using bash, put it in your .bashrc instead.

I also just tried setting tmux as my default shell (chsh -s $(which tmux)) and it seems to break direct command execution via SSH, e.g. ssh $some_server echo foo will not produce any output.

share|improve this answer

None of the above responses worked for me - exec tmux prevents me closing tmux without quitting the shell (whether it's opened with Ctrl + T or from the application menu).

I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B does some sort of convoluted bash -exec(vim) statement to edit my .bashrc, so it acts like a regular shell.

tmux loaded rather than vim under that situation after placing the above at the top of my .bashrc. I've wrapped the tmux executing line in another if statement, checking that it's running in interactive mode.

if command -v tmux>/dev/null; then
        if [ ! -z "$PS1" ]; then # unless shell not loaded interactively, run tmux
                [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && tmux

You could wrap all that onto one line but for readability I think that's fine.

share|improve this answer
Adding a ampersand would solved that issue like so. [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && exec tmux & – Daniel Chateau Oct 6 '15 at 20:21

Adding to @Louis Maddox 's answer, I would execute tmux part with;

(exec tmux attach || exec tmux new-session)
share|improve this answer
I use exec sh -c 'tmux a || tmux', which (after looking at your answer) will probably make bad things happen if tmux can't start for any reason..... thanks, I'll use yours from now on :) – Mark K Cowan Dec 8 '15 at 12:22
tmux new -A -s mysession will probably work too. – poolie Apr 22 at 1:16

Go to terminal preferances. enter image description here

And then click to "command" bar. enter image description here

Check the "Run a custom command instead of my sell" and write whatever command you want to execute at the startup of your terminal.

share|improve this answer

Add this into your ~/.tmux.conf

set -g default-command /usr/local/bin/fish
share|improve this answer

As Mikel already stated in his comment to have tmux as your login shell can have side effects. But you can make tmux your default shell, literally. A user's default shell is defined in /etc/passwd. So you can become root and edit /etc/passwd, e.g. sudo vi /etc/passwd search for the line that begins with your username. It probably ends with :/bin/bash. Change /bin/bash to /usr/bin/tmux and now tmux is your default login shell.

However, no guarantee that this won't cause problems!

What may work better is to NOT do anything that requries root privileges. I would try to create a file in my home directoy named .bash_login and start tmux from within that file: `echo "tmux" >~/.bash_login.

This should work, but you have to try and find our yourself, b/c the bash documentation is not very exact about what file is read and executed when.

share|improve this answer
What your first paragraph describes is what chsh does! Except that your way requires being root and is error-prone. Running tmux from .bash_login is more likely to break remote logins. – Gilles Jul 20 '12 at 23:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.