CLI sharing and session management in Linux with 'screen' - A Quick-Start Guide

AID: 4595
  • Status: Published

2220 points

  • ByAnton74
  • TypeTutorial
  • Posted on2011-02-24 at 22:47:02

Using 'screen' for session sharing, The Simple Edition


  • Step 1: user starts session with command: screen

  • Step 2: other user (logged in with same user account) connects with command: screen -x

Done. Both users are connected to the same CLI session, and can both see what's being typed, and can both type.

But it is not only good for session sharing with another person, the ability to have multiple windows in a single session, and being able to disconnect and re-connect (much like you can with RDP) among other things can be quite useful for any user:


A few more things we can do


There is a control character which is used to initiate all commands (everything that's not the control character is passed to the session). The default control character is Ctrl-A.

There is a site-wide /etc/screenrc file, and optionally a .screenrc file in a home directory, in which options like the control character can be set.

Some basic commands:

  • Ctrl-A C: create a new window

  • Ctrl-A N: switch to next window

  • Ctrl-A P: switch to previous window

  • Ctrl-A ”: show window list (from which you can switch to any window)

  • Ctrl-A [: Enter Copy-n-Paste/Scrollback mode (exit with Esc)

  • Ctrl-A D: detach from screen (which remains running). This is like disconnecting an RDP session.

Some command line options

  • List screen sessions: screen -ls

  • Reattach if possible, otherwise start new session: screen -R

  • Attach to specific session: screen -r <sessionname>

  • Detach already-attached clients and attach to the first session listed: screen -D -RR

Like explained above, to multi-attach (share a session), you can simply run ”screen -x” which will attach to an existing session without detaching existing users. The -x option can be combined with other options to enable multi-attach.


Exiting (or not)


If you lose your connection or close/kill your SSH session, screen will not exit but detach and remain running, so you can log back in and reattach to the same session.

If you exit a shell, that screen window will close (alternate: Ctrl-A K). If there are no more remaining windows, screen will exit.

--

Reference: http://www.commandlinefu.com/commands/view/2225/share-a-screen-session
Reference: http://www.linuxjournal.com/article/6340
Asked On
2011-02-24 at 22:47:02ID4595
Tags

Linux

,

CLI

,

command line

,

session

,

sharing

,

background

,

screen

,

utility

Topic

Linux Administration

Views
1028

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top Linux Admin Experts

  1. maeltar

    4,300

    0 points yesterday

    Profile
    Rank: Guru
  2. xterm

    4,000

    0 points yesterday

    Profile
    Rank: Sage
  3. noci

    2,800

    0 points yesterday

    Profile
    Rank: Genius
  4. duncan_roe

    2,800

    0 points yesterday

    Profile
    Rank: Genius
  5. pcsmitpra

    1,800

    0 points yesterday

    Profile
    Rank: Wizard
  6. testez

    1,800

    0 points yesterday

    Profile
    Rank: Guru
  7. Nopius

    1,470

    30 points yesterday

    Profile
    Rank: Genius
  8. abbright

    1,000

    0 points yesterday

    Profile
    Rank: Guru
  9. torakeshb

    1,000

    0 points yesterday

    Profile
    Rank: Master
  10. woolmilkporc

    800

    0 points yesterday

    Profile
    Rank: Genius
  11. dbauermann

    600

    0 points yesterday

    Profile
  12. wasimibm

    600

    0 points yesterday

    Profile
    Rank: Guru
  13. unassassinable

    420

    0 points yesterday

    Profile
    Rank: Guru
  14. Anton74

    390

    0 points yesterday

    Profile
    Rank: Guru
  15. kosarajudeepak

    340

    0 points yesterday

    Profile
    Rank: Wizard
  16. abolinhas

    320

    0 points yesterday

    Profile
    Rank: Guru
  17. viju2008

    300

    0 points yesterday

    Profile
    Rank: Master
  18. farzanj

    300

    0 points yesterday

    Profile
    Rank: Genius
  19. OP_Zaharin

    300

    0 points yesterday

    Profile
    Rank: Sage
  20. ahmedhamdy27

    290

    0 points yesterday

    Profile
  21. allen-davis

    280

    10 points yesterday

    Profile
    Rank: Master

Hall Of Fame