Auto Attach to tmux session on SSH
To start tmux and attach to existing connection on SSH in, edit file
1 |
vi ~/.bashrc |
Add
1 2 3 4 5 6 7 8 |
if [[ "$TMUX" == "" ]] && [[ "$SSH_CONNECTION" != "" ]] && [ "$SSH_TTY" != "" ]; then WHOAMI=$(whoami) if tmux has-session -t $WHOAMI 2>/dev/null; then tmux -2 attach-session -t $WHOAMI else tmux -2 new-session -s $WHOAMI fi fi |
Method 2
You can use following command when connecting to remote sevrer.
1 |
ssh USER@SERVER_IP -t tmux a |