I auto start gnu screen when I ssh into one on my own servers. When I am done, I have to d to detach. Then exit to quit ssh. This means that when I ssh into the server again at some point in time, I can continue where I left off.
Can I create a alias (for instance) that will (from within screen) detach and drop ssh?
Best Answer
Starting
screen
when logging in on the remote host (executed on your local machine):In the screen session, on the remote host, to detach and log out (which would end the SSH session unless you are using a persistent connection using a control socket (i.e. using the
ControlMaster
setting withControlPersist
in~/.ssh/config
)):Later, to log in and re-attach:
Note that you have to use
-t
withssh
, forcing pseudo-terminal allocation, to startscreen
in this way.The alias on the remote host would be for
screen -d
, maybedetach='screen -d'
or something similar.On the local host, you could have a section in your
~/.ssh/config
file sayingThen, whenever you use
a
screen
session would be created (or re-attached to) on the specified host, whilewould not use
screen
.Note:
RemoteCommand
was added in OpenSSH 7.6 (2017-10-03).For
tmux
:tmux new-session -A -s "%n"
in~/.ssh/config
instead ofscreen -d -R
.tmux detach-client
ortmux detach
to detach.