2

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

3
  • 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. Commented Apr 30, 2014 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 Commented Apr 30, 2014 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 ~~.. Commented Apr 30, 2014 at 21:32

2 Answers 2

2

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.

3
  • 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. Commented Apr 30, 2014 at 22:41
  • Depends on the pain, but you are right Commented Apr 30, 2014 at 23:52
  • Both great answers! Maybe update your answer to mention both solutions and then it can be accepted? Commented Apr 4, 2022 at 15:45
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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.