I want tmux to start on ssh login.
The typical advice is to add this to ~/.bashrc:
if [ -z "$TMUX" ] && [ -n "$SSH_TTY" ] && [[ $- =~ i ]]; then
tmux attach-session -t mysession 2>/dev/null || tmux new-session -s mysession
fi
But when I log in, I get this error from tmux:
lost server
...And then I'm in bash as usual.
UPDATE
When I add a sleep:
if [ -z "$TMUX" ] && [ -n "$SSH_TTY" ] && [[ $- =~ i ]]; then
tmux attach-session -t mysession 2>/dev/null || $(sleep 1 && tmux new-session -s mysession)
fi
...then it works. Strange! What is the reason?