1

Case scenario:

When I open my terminal, screen starts automatically. This is useful because I often need multiple screens locally within the same terminal.

However, if I connect via SSH to a server and want to start a screen session on that server, it will create a local screen session instead.

i.e I want a parent (local screen) /children (remote screens) relationship between (or equivalent) instead of multiple SSH connections via local screens

hbt
  • 143
  • 6
  • Can you clarify what you mean 'it will create a local screen sesssion instead'? When I run screen, then ssh and start a screen session on the remote system, it starts a session on the remote session as expected. –  Apr 30 '14 at 21:00
  • @yoonix Googled around and found examples with attach/detach and worked my way back. Posted clear answer below. Thanks for your help – hbt Apr 30 '14 at 21:15
  • Yep, same idea as with ssh itself. If you ssh to a host, then ssh to another host and hit `~.` it will detach you from the session closest to you. Each level you want to pass through you need to add an initial character. So for closing a nested ssh session you would `~~.`. –  Apr 30 '14 at 21:32

2 Answers2

1

Here is how:

Notice the @local vs @remote

user@local:$> screen

<Ctrl-a> c and a new local window is created

user@local:$> ssh user@remote

user@remote:$> screen

<Ctrl-a> a c and a new remote window is created

user@remote:$>

<Ctrl-a> c and a new local window is created

Basically <Ctrl-a> a [your screen command] allows you to call the sub-screen

hbt
  • 143
  • 6
1

If you want to run screen within another screen, you need to change screen control character combination (by default it's Ctrl + a).

Typically the first (outer) screen would be controlled with "Ctrl+a" (default), ie press "Ctrl+a" then "?" or "c"

Start screen within the screen (inner) with alternative control character, ie:

screen -e^Xx

Then you'd press "Ctrl+x" then "?" or "c" to operate inner screen.

Alec Istomin
  • 322
  • 1
  • 8
  • You don't need to change the control character. If you need send a command two levels deep you just press `CTRL-A A`, and then whatever you want to the far system. It is a pain though. – Zoredache Apr 30 '14 at 22:41
  • Depends on the pain, but you are right – Alec Istomin Apr 30 '14 at 23:52
  • Both great answers! Maybe update your answer to mention both solutions and then it can be accepted? – Acorn Apr 04 '22 at 15:45