Last Updated: September 22, 2018
· teamon

Always use tmux with ssh

Put this in your .zshrc/.bashrc

function ssht(){
  ssh $* -t 'tmux a || tmux || /bin/bash'


$ ssht user@host

will attach to existing tmux session, create new if one does not exist or just start bash if there is no tmux available.

2 Responses
Add your response


Love this tip, a small adjustment I made was to use the users default shell (where it isn't /bin/bash):

getent passwd $LOGNAME | cut -d: -f7

over 1 year ago ·

@teamon and then you're just one step away from what I consider to be the ideal ssh+tmux setup: http://goo.gl/XumZS9

over 1 year ago ·