Follow

Good morning, folks. Have a sysadmin tip:

When you ssh to a remote system, make it a habit to run either `screen` or `tmux` first. Always. Even for just a quick little command.

That way, when your crap ISP monopoly drops your connection for no reason whatsoever, your remote command won't be SIGHUP'd, & you can resume with `screen -r` or `tmux attach` when they decide your connection can be restored.

Also, to save yourself from nasty surprises, verify the hostname of the system you're on when you start a screen/tmux session. This tip doesn't work if you do it on your local machine instead of the remote.

ssh + tmux tip 

@arielmt if you wanted to go one step further you could add something like this to your ssh config:

Host * (or whatever)
RequestTTY yes
RemoteCommand tmux new -As %u@%L

this will create a new tmux session on the remote host, named after localuser@localhost* OR, if that session already exists, reattach to it automatically!

pros: no need to manually type 'tmux a' or add something like it to every .bashrc on every machine you ssh into.

cons: since it's a ptty it means detaching from or destroying a (any) tmux session kills the ssh connection as well, which might interfere with muscle memory a bit (but reconnecting is free and you STILL didn't lose any work)

if you're nesting a remote tmux session within a local one, you can extend this with "LocalCommand tmux rename-window %h" to rename your local pane to whatever remote host you're connecting to, but i haven't yet found a convenient way to undo this on disconnect (without manually toggling tmux automatic-rename)

* of course you can name the remote session to whatever you feel like, that's just an example. see TOKENS in ssh_config(5) for options other than %u / %L

@arielmt some of us done have crap ISPs. But good advice anyway…

@arielmt I use byobu for this as it always connects to the same and is very handy

@arielmt@computerfairi.es Also, if you're an idiot like me, make sure to make the PS1 of your vps VERY different from your own desktop one. So you avoid typing commands on your vps that were intended for the desktop and vice versa.

Sign in to participate in the conversation
Computer Fairies

Computer Fairies is a Mastodon instance that aims to be as queer, friendly and furry as possible. We welcome all kinds of computer fairies!