DEV Community

Discussion on: Persistent SSH Sessions with Tmux

Collapse
 
ncot_tech profile image
James

This is something I've been trying to do too, however I couldn't get your method to work on my setup (LXC containers inside Proxmox). It wouldn't create the initial tmux session.

However, I found this Stack Overflow question which has a useful answer:

stackoverflow.com/questions/343253...

Putting tmux new -A -s mySession in my .profile works.

I'm also using mosh to persist the connection when my PC goes to sleep.

Collapse
 
idoko profile image
Michael Okoko

Glad you got it to work, also, I've only heard praises for mosh. I should take it for a spin one of these days.

Collapse
 
sndp487 profile image
Sandeep

I was getting sessions should be nested with care, unset $TMUX to force at the top of tmux when using tmux attach || tmux new. What happens is tmux also executes .bashrc/profile.

So now I use this:

if [[ ! "$TERM" =~ "screen" ]]; then
tmux attach -t default || tmux new -s default
fi

in my .bashrc

TERM is set to 'screen' in tmux environment.