Screen

From Freephile Wiki
Revision as of 22:47, 25 April 2013 by Freephile (talk | contribs) (Created page with "Using GNU Screen is an indespensible tool if you spend any amount of time at the console (aka terminal) * http://news.softpedia.com/news/GNU-Screen-Tutorial-44274.shtml * http...")

(diff) ← Older revision | Approved revision (diff) | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Using GNU Screen is an indespensible tool if you spend any amount of time at the console (aka terminal)

Example: Long-lasting port-forwarding[edit | edit source]

You need access to a database on Machine A, your production database host. However, that machine is configured to only allow database connections "locally". The work needs to be done from machine B, another remote host where you do management and reporting. With screen and SSH port forwarding, you can do this, and the port-forwarding "tunnel" will not drop until you kill screen or reboot.

  1. login via SSH to remote host B
  2. start a screen session
  3. SSH to host A using port-forwarding so that local postgres connections tunnel to the production postgres server
  4. detach from screen session
ssh hostB.example.com
screen
ssh -v -L 55432:localhost:5432 user@hostA.example.com
Ctrl-a d

Until one of the hosts is rebooted, or you kill the screen session, that port-forwarding will work.

To reattach to the screen session,

  1. login to the host where you initiated the session
  2. issue the 'reattach' command
ssh hostB.example.com
screen -r

You can also get a listing of available sessions with Ctrl-a A

Scrolling and Movement[edit | edit source]

Screen works like vi in terms of cursor control. CTRL-a-[ will enter 'Copy' mode where you can move back in the scroll buffer

Help[edit | edit source]

see man screen of course, and tutorials like the one listed at that top of this article.

See Ctrl-a ? for a list of keybindings in screen