alias to detach screen when I exit (and kill ssh)

Vissie

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?

Kusalananda

Starting screen when logging in on the remote host (executed on your local machine):

ssh -t user@host screen

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 with ControlPersist in ~/.ssh/config)):

screen -d

Later, to log in and re-attach:

ssh -t user@host screen -r

Note that you have to use -t with ssh, forcing pseudo-terminal allocation, to start screen in this way.

The alias on the remote host would be for screen -d, maybe detach='screen -d' or something similar.

On the local host, you could have a section in your ~/.ssh/config file saying

Host *-screen
    RequestTTY force
    RemoteCommand screen -d -R

Host myhost myhost-screen
    HostName myhost.somedomain.example.com
    User myname

Then, whenever you use

ssh myhost-screen

a screen session would be created (or re-attached to) on the specified host, while

ssh myhost

would not use screen.

Note: RemoteCommand was added in OpenSSH 7.6 (2017-10-03).


For tmux:

  • Use tmux new-session -A -s "%n" in ~/.ssh/config instead of screen -d -R.
  • Use prefixd or tmux detach-client or tmux detach to detach.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how can i force screen to detach *instead of* exit/logout?

From Dev

how can i force screen to detach *instead of* exit/logout?

From Dev

How can processes detach when I try to kill them?

From Java

How do I force detach Screen from another SSH session?

From Dev

Attach, Detach and Kill a process in Screen with a bash script

From Dev

When writing a makefile how can I kill a subprocess on exit?

From Dev

Source by bashrc when I exit an 'ssh' session

From Dev

ssh, screen, run command and detach in one go?

From Dev

Detach from screen without Ctrl+a d in SSH

From Dev

Kill process spawned by ssh when ssh dies

From Dev

"screen" exit by itself after broken ssh?

From Dev

Detach screen in screen?

From Dev

How can I resume a screen that I did not manage to detach?

From Java

When should I use std::thread::detach?

From Dev

Kill a screen session when script is done executing

From Dev

How do I detach a screen session from a terminal?

From Dev

When I exit a screen, I should be asked: “Do you want to save?” codeigniter

From Dev

Kill backgrounded SSH when shell exits

From Dev

Kill backgrounded SSH when shell exits

From Dev

ssh -> screen -> ssh - how to kill remote screened ssh without killing original ssh session

From Dev

How do I prevent just 'exit' from being saved when I close an SSH connection?

From Dev

How to kill the thread in specific object when application exit in WPF?

From Dev

How can i have exit status of zero with kill command

From Dev

Can I use an SSH alias as part of a hostname?

From Dev

How can I alias a domain in .ssh/config?

From Dev

I trying to exit but getting an exception bad argument called as exit(undefined,kill)

From Dev

How to kill explorer.exe when it's frozen on the start screen?

From Java

How do I kill all of the enemy sprites on the screen?

From Dev

How do I kill a screen session if it has no running processes?

Related Related

  1. 1

    how can i force screen to detach *instead of* exit/logout?

  2. 2

    how can i force screen to detach *instead of* exit/logout?

  3. 3

    How can processes detach when I try to kill them?

  4. 4

    How do I force detach Screen from another SSH session?

  5. 5

    Attach, Detach and Kill a process in Screen with a bash script

  6. 6

    When writing a makefile how can I kill a subprocess on exit?

  7. 7

    Source by bashrc when I exit an 'ssh' session

  8. 8

    ssh, screen, run command and detach in one go?

  9. 9

    Detach from screen without Ctrl+a d in SSH

  10. 10

    Kill process spawned by ssh when ssh dies

  11. 11

    "screen" exit by itself after broken ssh?

  12. 12

    Detach screen in screen?

  13. 13

    How can I resume a screen that I did not manage to detach?

  14. 14

    When should I use std::thread::detach?

  15. 15

    Kill a screen session when script is done executing

  16. 16

    How do I detach a screen session from a terminal?

  17. 17

    When I exit a screen, I should be asked: “Do you want to save?” codeigniter

  18. 18

    Kill backgrounded SSH when shell exits

  19. 19

    Kill backgrounded SSH when shell exits

  20. 20

    ssh -> screen -> ssh - how to kill remote screened ssh without killing original ssh session

  21. 21

    How do I prevent just 'exit' from being saved when I close an SSH connection?

  22. 22

    How to kill the thread in specific object when application exit in WPF?

  23. 23

    How can i have exit status of zero with kill command

  24. 24

    Can I use an SSH alias as part of a hostname?

  25. 25

    How can I alias a domain in .ssh/config?

  26. 26

    I trying to exit but getting an exception bad argument called as exit(undefined,kill)

  27. 27

    How to kill explorer.exe when it's frozen on the start screen?

  28. 28

    How do I kill all of the enemy sprites on the screen?

  29. 29

    How do I kill a screen session if it has no running processes?

HotTag

Archive