20

Is it possible to run a gnu screen within a gnu screen? I'm not sure how the key bindings would work. I need to log into a server that is already running a screen session, from a local screen session.

20

You just hit ctrl-a followed by an a to actually send the ctrl-a to the nested screen instance.

4
  • 3
    No, as RobM correctly notes, you must type ctrl-a a to send ctrl-a to the nested screen. Jul 11 '11 at 16:17
  • 18
    Yo dawg. I heard you like screens, so I put a ctrl-a in your ctrl-a so you can screen while you screen.
    – user67218
    Feb 15 '12 at 17:46
  • 1
    Also works for remapped codes; my trigger is ctrl-g (because I like ctrl-a to go to the beginning of a line in bash), so in the nested session; ctrl-g g 2 selects window 2 in the nested screen, ctrl-g 1 selects window 1 in the initial screen.
    – jaygooby
    Mar 10 '14 at 12:10
  • Is there a way to send ctrl-a-a to existing screen session using stuff or equivalent?
    – sunknudsen
    Apr 20 at 19:29
10

Yes, it is possible. You will need to redefine screen's escape character, e.g. set it to E when you call screen

screen -e^Eq
1
  • this is a better answer, and what i was looking for. i wanted to just know how to configure it properly, NOT how to workaround. Why press more keys that you have to, rebind it on teh nest so you know which screen your controlling for sure. Mar 22 '16 at 21:11
9

If you clear the $STY environment variable, running screen will start a nested session.

You then have to send a literal ^a to the nested session before using any of your bindings. You can send a literla ^a by pressing ^a followed by a (plain).

So to create a new window in the nested session you would press ^a, a, c.

4

'Ctrl-a a' sends a ctrl-a to the nested screen.

eg, if you want to add a new tab, you do 'ctrl-a a c'

if you want to disconnect: 'ctrl-a a d'

1

The commands work fine if you use ctrl-a a or change the escape character. However, he also asked how to attach from inside another terminal. It took me a while to find this online, but after I saw the -m flag I looked it up in the manual.

    -m      cause screen  to  ignore  the  $STY environment variable. With
            "screen -m" creation of a new session is enforced, regardless whether screen is
            called from within another screen session or not. This flag has a special
            meaning in connection with the `-d' option:

    -d -m   Start screen in "detached" mode. This creates a new session but
            doesn't attach to it. This is useful for system startup scripts.

    -D -m   This also starts screen in "detached" mode, but doesn't fork a new
            process. The command exits if the session terminates.

After that I tested creating a new screen with

screen-d -m

and the attaching to it from within screen with

screen -R -D

and it worked the way I wanted, creating a new screen and attaching to it from withing screen. I don't think many people will use this functionality, but sometimes I run out of terminals so it may be useful to have grouped tabs in a seperate screen.

1
  • The selected answer do not explain it well, but for whatever reason I was not able to create the nested screens. So screen -m was really useful for me. Thanks for the in-depth startup process. May 8 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.