Turbocharge an SSH Connection with screen
Novell Cool Solutions: Feature
By Kirk Coombs
Digg This -
Posted: 15 Sep 2005
- SUSE Linux Professional
- SUSE Linux Enterprise Server
- Open Enterprise Server
- Novell Linux Desktop
SSH provides a great mechanism for gaining shell access to a remote
computer. It does have some limitations, however:
- It does not allow for more than one shell session per connection. If multiple sessions are needed, more SSH connections need to be created. This results in more windows to deal with on the client.
- If a SSH connection is broken, and processes that were running in
it are immediately terminated.
screen is a handy utility which fixes these
screen is installed on a remote
computer (and it
is by default on all SUSE distributions), then a user can SSH into that
computer then use
screen to add more sessions, copy and
between these sessions, and keep the sessions alive across SSH
screen does not have to be used in
conjunction with SSH, but it makes most sense to do so.
A Quick screen Example
As an example, consider two computers zeus and hades. A user on zeus would like to connect to hades and use two programs at the
same time, say
vi. Do do so, the
user simply needs to SSH into hades and
screen command, as shown.
As soon as
screen launches it displays a splash
screen. Pressing the space key
returns the user to the command prompt.
screen is active, and can be used to launch
additional programs. To launch another program and maintain the
current command-prompt use:
# screen program_name
The new programs are launched in their own 'screen'. These are
numbered 0-9, starting at 0. In this case, the command-prompt is
on screen 0,
top is on screen 1, and
on screen 2. To switch between the screens, use CTRL-a [0-9]. For example,
screen top the application is launched in
own 'screen'. To return to the command-prompt to launch
hold CTRL and press a. Release both of them, and
All command-keys in
screen begin the the sequence, CTRL-a. Another great command
is ". Press CTRL-a then " and a list of the current screens
is listed. Simply navigate them with the arrow keys to select the
After launching both programs, return to the command-prompt on
screen 0, and type
Notice that the
vi process both are
sub-processes of screen.
Now, simulate a broken SSH connection by closing the window.
If this were a typical connection, both
would immediately terminate. With
screen they do
not. Initiate a new SSH connection then pull up a list of the
available screen sessions by entering:
# screen -ls
Notice that there is an active session. Multiple sessions can exist at once. To re-connect to a session, enter:
# screen -r <session name>
screen also has great copy and paste support. To
copy, execute the command: CTRL-a [.
This enters copy mode. Use the arrow keys to move the cursor to
the beginning of a selection, then hit space.
Move the cursor with the arrow keys to create the selection then hit space again to signal the end of the
selection. Now, go to to desired paste location (in the current
screen or a different screen). Type
CTRL-a ] to paste the selection.
screen simply exit each program on each
then type exit on the final
command-prompt. To exit all screens at once, type CTRL-a :exit.
Additional screen Options
This example only scratched the surface of what
can do. For more information see the info pages (info screen), the man page (man screen), or the online help
(CTRL-a ?). There is also a
great WIKI page at http://gentoo-wiki.com/TIP_Using_screen.
Following are some of the more common functions. Remember all functions are preceded with CTRL-a.
||Create a new screen. This
creates a new screen with a shell. It is an alternative to using
||Switch to the desired screen.
||Give a list of the current
||Activate the online help
||Begin copy mode. To make a
selection use the arrow-keys to move to the beginning of the selection
and press space.
Continue the selection and press space
||Paste a copied selection.
||Split the current view. This
creates an empty pane that other screens can be displayed in.
||Remove the current split view.
||Switch to another pane in a
||Kill a screen window.
||Detach the current screen
Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com