Ref: https://gist.github.com/jctosta/af918e1618682638aa82
apt-get install screen
(optional) For Azure, use az cli to write a local SSH configfor your user to use SSO creds
az ssh config --ip 1.2.3.4 --file az_ssh_config
This will automatically use your (ephemeral) Azure keypair generated above for SSH connections. You will have to regenerate those based on their expiry
ssh -t -A $hostname screen -R
This will create a new screen session or reattach to the most recent screen
This command can be run multiple times and do what you expect (i.e. it's idempotent)
(optional) Use -S <session_name>
to set a name for your session, then use -r <session_name>
to attach to that specific session. This is useful when pair-programming and collaborating on the same box, as screen
supports multi-user mode
Hit Ctrl+A then press a key to send a command to screen (typically a single char)
- d = detach from screen (it will continue running)
- c = Create new window in same screen session
- Ctrl+A again - Swap to prior window
- [#] to switch to window #
- " = Choose window from list
- k = kill window (or Ctrl +D or
exit
)
ssh -t -A $hostname screen -ls