DEV Community


Discussion on: Persistent SSH Sessions with Tmux

ncot_tech profile image

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:

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.

idoko profile image
Michael Okoko Author

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.

sndp487 profile image

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

in my .bashrc

TERM is set to 'screen' in tmux environment.

Forem Open with the Forem app