This is a short Screen for Unix and Linux: HowTo and Reference for everyday use. This quick screen tutorial and reference guide aims to provide the most commonly used features of this very useful utility. When working with multiple ssh terminals it's handy to save a session especially where typing passwords is required often or you need to jump a number of places to reach your target host.
This is where screen comes in handy. Screen creates a terminal that's detached from your current session so the screen can be connected to or reconnected upon exit from screen. To start a session in screen, enter the following:
|# screen -S [SESSION NAME]||The Session Name you wish to assign.|
|CTRL + a + [0-9]||Numbers 0 to 9 to switch internal sessions (omit the plus signs)|
|# screen -ls||List sessions you've opened.|
|# screen -d -R [SESSION NAME]||Resume earlier started session.|
|CTRL + a + d||Disconnect from screen to reconnect later.|
|CTRL + a + [SPACE]||Toggle through the sessions that have been opened.|
CTRL + SHIFT + a + :
Then at the : prompt type the word password. At the prompt enter the password you wish to use:
New screen password: <SECRET>
Then again a second time:
Retype new password:<SECRET>
|Set a password for your session.|
|CTRL + a + c||Create a new window within the same screen session so you can connect to another machine.|
|CTRL + SHIFT + a + : (CTRL + SHIFT + a then SHIFT + : then at the : CLI type kill)||Kill an internal screen hung session.|
This is just a small everyday command type of reference to get you by. Screen also comes with quite the set of features. For a full list, see the man page for screen available on the command line by typing # man screen or by typing # screen –help. To install screen the yum utility can be used to search for it on RHEL systems, for example then installed in this manner if not available:
-bash: screen: command not found
# yum search screen
screen.x86_64 : A screen manager that supports multiple logins on one terminal
# yum install screen
Package Arch Version Repository Size
screen x86_64 4.0.3-16.el6 sl 493 k
# which screen
# screen –help
Use: screen [-opts] [cmd [args]]
or: screen -r [host.tty]
-4 Use IPv4.
-6 Use IPv6.
-a Force all capabilities into each window's termcap.
-A -[r|R] Adapt all windows to the new display width & height.
-c file Read configuration file instead of '.screenrc'.
-d (-r) Detach the elsewhere running screen (and reattach here).
-dmS name Start as daemon: Screen session in detached mode.
-D (-r) Detach and logout remote (and reattach here).
-D -RR Do whatever is needed to get a screen session.
-e xy Change command characters.
-f Flow control on, -fn = off, -fa = auto.
-h lines Set the size of the scrollback history buffer.
-i Interrupt output sooner when flow control is on.
-l Login mode on (update /var/run/utmp), -ln = off.
-list or -ls. Do nothing, just list our SockDir.
-L Turn on output logging.
-m ignore $STY variable, do create a new screen session.
-O Choose optimal output rather than exact vt100 emulation.
-p window Preselect the named window if it exists.
-q Quiet startup. Exits with non-zero return code if unsuccessful.
-r Reattach to a detached screen process.
-R Reattach if possible, otherwise start a new session.
-s shell Shell to execute rather than $SHELL.
-S sockname Name this session <pid>.sockname instead of <pid>.<tty>.<host>.
-t title Set title. (window's name).
-T term Use term as $TERM for windows, rather than "screen".
-U Tell screen to use UTF-8 encoding.
-v Print "Screen version 4.00.03 (FAU) 23-Oct-06".
-wipe Do nothing, just clean up SockDir.
-x Attach to a not detached screen. (Multi display mode).
-X Execute <cmd> as a screen command in the specified session.