Screen: Difference between revisions
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..." |
m Text replacement - "<(\/?)source" to "<$1syntaxhighlight" |
||
Line 10: | Line 10: | ||
# detach from screen session | # detach from screen session | ||
< | <syntaxhighlight lang="bash"> | ||
ssh hostB.example.com | ssh hostB.example.com | ||
screen | screen | ||
ssh -v -L 55432:localhost:5432 user@hostA.example.com | ssh -v -L 55432:localhost:5432 user@hostA.example.com | ||
Ctrl-a d | Ctrl-a d | ||
</ | </syntaxhighlight> | ||
Until one of the hosts is rebooted, or you kill the screen session, that port-forwarding will work. | Until one of the hosts is rebooted, or you kill the screen session, that port-forwarding will work. | ||
Line 23: | Line 23: | ||
# issue the 'reattach' command | # issue the 'reattach' command | ||
< | <syntaxhighlight lang="bash"> | ||
ssh hostB.example.com | ssh hostB.example.com | ||
screen -r | screen -r | ||
</ | </syntaxhighlight> | ||
You can also get a listing of available sessions with <code>Ctrl-a A</code> | You can also get a listing of available sessions with <code>Ctrl-a A</code> |
Latest revision as of 13:34, 24 February 2025
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://www.rackaid.com/resources/linux-screen-tutorial-and-how-to/
Example: Long-lasting port-forwarding[edit]
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.
- login via SSH to remote host B
- start a screen session
- SSH to host A using port-forwarding so that local postgres connections tunnel to the production postgres server
- 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,
- login to the host where you initiated the session
- 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]
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]
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