Difference between revisions of "GNU Screen"

From ArchWiki
Jump to: navigation, search
m (Use 256 Colors with Rxvt-Unicode (urxvt))
(43 intermediate revisions by 16 users not shown)
Line 1: Line 1:
[[Category:Utilities (English)]]
+
[[Category:System administration]]
[[Category:HOWTOs (English)]]
+
[[ru:GNU Screen]]
GNU Screen is a wrapper that allows separation between the text program and the shell from which it was launched. This allows the user to, for example, start a text program in a terminal in X, kill X, and continue to interact with the program. Here are a couple of tips and tricks you may be interested in.
+
[[zh-CN:GNU Screen]]
 +
[http://www.gnu.org/s/screen/ GNU Screen] is a wrapper that allows separation between the text program and the shell from which it was launched. This allows the user to, for example, start a text program in a terminal in X, kill X, and continue to interact with the program. Here are a couple of tips and tricks you may be interested in.
  
If you are looking for a tutorial, the gentoo wiki contains a nice one: http://en.gentoo-wiki.com/wiki/Screen
+
== Installation ==
  
== Basics ==
+
GNU Screen can be [[pacman|installed]] using the {{pkg|screen}} package found in the [[Official Repositories|official repositories]].
Commands are entered pressing Control A and then the key binding. The escape key can be changed with the ''escape'' option in ~/.screenrc. IE:
+
<pre>
+
escape ``
+
</pre>
+
sets the escape key to `
+
  
 +
== Usage ==
 +
Commands are entered pressing {{keypress|ctrl+a}} and then the key binding.
 
=== Common Commands ===
 
=== Common Commands ===
C-a ?
+
* {{keypress|ctrl+a}} {{keypress|?}} Displays commands and its defaults (VERY important)
:Displays commands and it's defaults (VERY important :p)
+
* {{keypress|ctrl+a}} {{keypress|:}} Enter to the command prompt of screen
C-a "
+
* {{keypress|ctrl+a}} {{keypress|"}} Window list
:Window list
+
* {{keypress|ctrl+a}} {{keypress|0}} opens window 0
C-a 0
+
* {{keypress|ctrl+a}} {{keypress|A}} Rename the current window
:opens window 0
+
* {{keypress|ctrl+a}} {{keypress|a}} Sends {{keypress|ctrl+a}} to the current window
C-a A
+
* {{keypress|ctrl+a}} {{keypress|c}} Create a new window (with shell)
:Rename the current window
+
* {{keypress|ctrl+a}} {{keypress|S}} Split current region into two regions
C-a c
+
* {{keypress|ctrl+a}} {{keypress|tab}} Switch the input focus to the next region
:Create a new window (with shell)
+
* {{keypress|ctrl+a}} {{keypress|ctrl+a}} Toggle between current and previous region
C-a S
+
* {{keypress|ctrl+a}} {{keypress|Esc}} Enter Copy Mode (use enter to select a range of text)
:Split current region into two regions
+
* {{keypress|ctrl+a}} {{keypress|]}} Paste text
C-a <TAB>
+
* {{keypress|ctrl+a}} {{keypress|Q}} Close all regions but the current one
:Switch the input focus to the next region
+
* {{keypress|ctrl+a}} {{keypress|X}} Close the current region
C-a C-a
+
* {{keypress|ctrl+a}} {{keypress|d}} Detach from the current screen session, and leave it running. Use {{ic|screen -r}} to resume
:Focus on next region
+
C-a <ESC>
+
:Enter Copy Mode (use enter to select a range of text)
+
C-a ]
+
:Paste text
+
C-a Q
+
:Close all regions but the current one
+
C-a d
+
:Detach from the current screen session, and leave it running. Use screen -r to resume
+
  
== Start at window 1 ==
+
== Tips and tricks ==
By default, the first screen window is 0. If you'd rather never have a window 0 and start instead with 1, put something like the following in your ~/.screenrc:
+
=== Change the escape key ===
<pre>
+
The escape key can be changed with the {{ic|escape}} option in {{ic|~/.screenrc}}. For example:
 +
{{bc|escape ``}}
 +
 
 +
sets the escape key to {{Keypress|`}}.
 +
 
 +
=== Start at window 1 ===
 +
By default, the first screen window is 0. If you'd rather never have a window 0 and start instead with 1, add the following lines on your configuration:
 +
{{hc|$HOME/.screenrc|
 
bind c screen 1
 
bind c screen 1
 +
bind ^c screen 1
 
bind 0 select 10                                                             
 
bind 0 select 10                                                             
 
screen 1
 
screen 1
select 1
+
}}
</pre>
+
=== Nested Screen Sessions ===
 
+
It is possible to get stuck in a nested screen session. A common scenario: you start an ssh session from within a screen session. Within the ssh session, you start screen. By default, the outer screen session that was launched first responds to {{keypress|ctrl+a}} commands. To send a command to the inner screen session, use {{keypress|ctrl+a}} {{keypress|a}}, followed by your command. For example:
== Nested Screen Sessions ==
+
* {{keypress|ctrl+a}} {{keypress|a}} {{keypress|d}} Detaches the inner screen session.
It's possible to get stuck in a nested screen session. A common scenario: you start an ssh session from within a screen session. Within the ssh session, you start screen. By default, the outer screen session that was launched first responds to C-a commands. To send a command to the inner screen session, use C-a a, followed by your command. For example:
+
* {{keypress|ctrl+a}} {{keypress|a}} {{keypress|K}} Kills the inner screen session.
  
C-a a d
+
=== Use 256 colors ===
:Detaches the inner screen session.
+
C-a a K
+
:Kills the inner screen session.
+
 
+
== Fix for residual editor text ==
+
When you open a text editor like nano in screen and then close it, the text may stay visible in your terminal. To fix this, put the following in your ~/.screenrc:
+
<pre>
+
altscreen on
+
</pre>
+
 
+
== Use 256 colors ==
+
 
By default, screen uses an 8-color terminal emulator. Use the following line to enable more colors, which is useful if you are using a more-capable terminal emulator:
 
By default, screen uses an 8-color terminal emulator. Use the following line to enable more colors, which is useful if you are using a more-capable terminal emulator:
<pre>
+
{{hc|$HOME/.screenrc|
 
term screen-256color
 
term screen-256color
</pre>
+
}}
  
== Use 256 Colors with Rxvt-Unicode (urxvt) ==
+
If this fails to render 256 colors in [[xterm]], try the following instead:
If you are using rxvt-unicode-256color from community, you may need to add this line in your ~/.screenrc to enable 256 colors while in screen.
+
{{hc|$HOME/.screenrc|<nowiki>
<pre>
+
attrcolor b ".I"    # allow bold colors - necessary for some reason
 +
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'  # tell screen how to set colors. AB = background, AF=foreground
 +
defbce on    # use current bg color for erased chars
 +
</nowiki>}}
 +
 
 +
=== Use 256 Colors with Rxvt-Unicode (urxvt) ===
 +
If you are using {{pkg|rxvt-unicode}} from the [[Official Repositories|official repositories]], you may need to add this line in your {{ic|~/.screenrc}} to enable 256 colors while in screen.
 +
{{hc|$HOME/.screenrc|<nowiki>
 
terminfo rxvt-unicode 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
 
terminfo rxvt-unicode 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
</pre>
+
</nowiki>}}
  
== Informative statusbar ==
+
=== Informative statusbar ===
 
The default statusbar may be a little lacking. You may find this one more helpful:
 
The default statusbar may be a little lacking. You may find this one more helpful:
<pre>
+
{{hc|$HOME/.screenrc|<nowiki>
 
hardstatus off
 
hardstatus off
 
hardstatus alwayslastline
 
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d
+
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W} %c %{g}]'
%{W} %c %{g}]'
+
</nowiki>}}
</pre>
+
=== Turn welcome message off ===
 
+
{{hc|$HOME/.screenrc|
== Turn welcome message off ==  
+
Cause it's annoying. Add to ~/.screenrc:
+
<pre>
+
 
startup_message off
 
startup_message off
</pre>
+
}}
 
+
== Turn your hardstatus line into a dynamic urxvt|xterm|aterm window title ==
+
This one's pretty simple; just switch your current hardstatus line into a caption line with notification, and edit accordingly:
+
  
<pre>
+
=== Turn your hardstatus line into a dynamic urxvt|xterm|aterm window title ===
 +
This one is pretty simple; just switch your current {{ic|hardstatus}} line into a {{ic|caption}} line with notification, and edit accordingly:
 +
{{hc|$HOME/.screenrc|<nowiki>
 
backtick 1 5 5 true
 
backtick 1 5 5 true
 
termcapinfo rxvt* 'hs:ts=\E]2;:fs=\007:ds=\E]2;\007'
 
termcapinfo rxvt* 'hs:ts=\E]2;:fs=\007:ds=\E]2;\007'
Line 97: Line 86:
 
caption string "%{= kw}%Y-%m-%d;%c %{= kw}%-Lw%{= kG}%{+b}[%n %t]%{-b}%{= kw}%+Lw%1`"
 
caption string "%{= kw}%Y-%m-%d;%c %{= kw}%-Lw%{= kG}%{+b}[%n %t]%{-b}%{= kw}%+Lw%1`"
 
caption always
 
caption always
</pre>
+
</nowiki>}}
  
This will give you something like "screen (0 bash)" in the title of your terminal emulator. The caption supplies the date, current time, and colorizes your screen window collection.
+
This will give you something like {{ic|screen (0 bash)}} in the title of your terminal emulator. The caption supplies the date, current time, and colorizes your screen window collection.
  
==Use X scrolling mechanism==
+
===Use X scrolling mechanism===
The scroll buffer of GNU Screen can be accessed with C-a [. However, this is very inconvenient. To use the scroll bar of e.g. xterm or konsole, add the following line to ~/.screenrc
+
The scroll buffer of GNU Screen can be accessed with {{keypress|ctrl+a}} {{keypress|[}}. However, this is very inconvenient. To use the scroll bar of e.g. xterm or konsole, add the following line:
termcapinfo xterm* ti@:te@
+
{{hc|$HOME/.screenrc|
 +
termcapinfo xterm* ti@:te@
 +
}}
  
==Add a GRUB entry to boot into Screen==
+
=== Attatch an existing running program to screen ===
If you mostly use X but occasionally want to run a Screen-as-window-manager session, here's one way to do it by adding a GRUB entry for Screen on a virtual console (text terminal).  
+
If you started a program outside screen, but now you would like it to be inside, you can use '''reptyr''' to reparent the process from it's current tty to one inside screen.
  
GRUB allows you to designate what runlevel you want so we'll use runlevel 4 for this purpose. Clone an appropriate GRUB entry and add a '4' to the kernel boot parameters list, like so:
+
[[Pacman|Install]] the package {{Pkg|reptyr}} from the [[Official Repositories]].
  
<pre>
+
Get the PID of the process (you can use {{ic|ps ax}} for that). Now just enter the PID as argument to reptyr inside a screen window.
 +
{{bc|$ reptyr ''<pid>''}}
 +
 
 +
===Add a GRUB entry to boot into Screen===
 +
{{Out of date|[https://www.archlinux.org/news/end-of-initscripts-support/ Initscripts] is deprecated, and the use of runlevels as well. Also, this instructions are for legacy GRUB}}
 +
If you mostly use [[Xorg|X]] but occasionally want to run a Screen-as-window-manager session, here is one way to do it by adding a [[GRUB]] entry for Screen on a virtual console (text terminal).
 +
 
 +
GRUB allows you to designate what runlevel you want so we will use runlevel 4 for this purpose. Clone an appropriate GRUB entry and add a {{ic|4}} to the kernel boot parameters list, like so:
 +
{{bc|1=
 
# (0) Arch Linux
 
# (0) Arch Linux
 
title  Arch Linux Screen
 
title  Arch Linux Screen
 
root  (hd0,2)
 
root  (hd0,2)
kernel /boot/vmlinuz26 root=/dev/disk/your_disk ro acpi_no_auto_ssdt irqpoll 4
+
kernel /vmlinuz-linux root=/dev/disk/your_disk ro acpi_no_auto_ssdt irqpoll 4
initrd /boot/kernel26.img
+
initrd /initramfs-linux.img
</pre>
+
}}
  
Add some entries to /etc/inittab to indicate what should happen on runlevel 4, substituting your user name for <user>:
+
Add some entries to {{ic|/etc/inittab}} to indicate what should happen on runlevel 4, substituting your user name for <user>:
<pre>
+
{{bc|# GNU Screen on runlevel 4
# gnu screen on rl4
+
 
scr2:4:respawn:/sbin/mingetty --autologin <user> tty1 linux
 
scr2:4:respawn:/sbin/mingetty --autologin <user> tty1 linux
</pre>
+
}}
The line uses mingetty to [[automatically login some user to a virtual console on startup]]. You will need to install the [http://aur.archlinux.org/packages.php?ID=13793 mingetty package] (AUR). The inittab line segments are separated by colons. The first part (scr*) is simply an id. The second part is the runlevel: This should only happen on runlevel 4 (which isn't used in any default setup - 3 is by default for a tty login and 5 is for X). 'Respawn' causes  init to repeat the command (i.e. autologin) if the user logs out.
+
We'll need to see that nothing else happens on virtual console 1 when we use runlevel 4, so remove '4' from the the first of the agetty lines:
+
  
<pre>c1:235:respawn:/sbin/agetty -8 38400 vc/1 linux</pre>
+
The above line uses mingetty to [[automatically login some user to a virtual console on startup]]. You will need to install the {{pkg|mingetty}} package from the [[Official Repositories|official repositories]]. The inittab line segments are separated by colons. The first part (scr*) is simply an id. The second part is the runlevel: This should only happen on runlevel 4 (which is not used in any default setup - 3 is by default for a tty login and 5 is for X). 'Respawn' causes init to repeat the command (i.e. autologin) if the user logs out.
 +
We will need to see that nothing else happens on virtual console 1 when we use runlevel 4, so remove {{ic|4}} from the the first of the agetty lines:
  
Once logged in we want to ensure that screen is started. Add the following to the end of your .bash_profile:
+
{{bc|c1:235:respawn:/sbin/agetty -8 38400 vc/1 linux}}
<pre>
+
  vico="$(tty | grep -oE ....$)"
+
  case "$vico" in
+
tty1) TERM=screen; exec /usr/bin/screen -R arch;;
+
  esac
+
  
</pre>
+
Once we are logged in, we want to ensure that screen is started. Add the following to the end of your {{ic|~/.bash_profile}}:
This checks for the current runlevel and will launch a screen session immediately after the autologin if the runlevel is 4.
+
{{bc|<nowiki>
 +
vico="$(tty | grep -oE ....$)"
 +
case "$vico" in
 +
  tty1) TERM=screen; exec /usr/bin/screen -R arch;;
 +
esac
 +
</nowiki>}}
 +
This checks for the current runlevel and will launch a screen session immediately after the automatic login if the runlevel is 4.
  
This can also be adapted to run screen on a virtual console next to X, simply checking for the current tty instead of the current runlevel. This check to see if we're on virtual console 3:
+
This can also be adapted to run screen on a virtual console next to X, simply checking for the current tty instead of the current runlevel. This checks to see if we are on virtual console 3:
<pre>
+
{{bc|<nowiki>
  vico="$(tty | grep -oE ....$)"
+
vico="$(tty | grep -oE ....$)"
  case "$vico" in
+
case "$vico" in
vc/3) TERM=screen; exec /usr/bin/screen;;
+
  vc/3) TERM=screen; exec /usr/bin/screen;;
  esac
+
esac
</pre>
+
</nowiki>}}
Set inittab/mingetty to automaically log in to vc/3 on runlevel 5 and you're set.
+
Set inittab/mingetty to automatically log in to vc/3 on runlevel 5 and you are set.
 +
 
 +
===Setting a different bash prompt while in screen===
 +
If you want a different bash prompt when in a screen session, add the following to your .bashrc:
 +
{{bc|<nowiki>
 +
if [ -z $STY ]
 +
then
 +
        PS1="YOUR REGULAR PROMPT"
 +
else 
 +
        PS1="YOUR SCREEN PROMPT"
 +
fi
 +
</nowiki>}}
 +
[http://serverfault.com/questions/257975/how-to-check-if-im-in-screen-session]
 +
 
 +
== Troubleshooting ==
 +
=== Fix Midnight Commander hard hang when starting in screen ===
 +
In some cases (need deeper inspection) [https://bugzilla.redhat.com/show_bug.cgi?id=168076 old gpm bug] gets alive. So, then you try to run mc inside screen, you get a frozen screen window. Try to kill gpm daemon before starting mc and/or disable it in {{ic|/etc/[[rc.conf]]}}.
 +
 
 +
=== Fix for residual editor text ===
 +
When you open a text editor like nano in screen and then close it, the text may stay visible in your terminal. To fix this, put the following:
 +
{{hc|$HOME/.screenrc|
 +
altscreen on
 +
}}
  
 
== See Also ==
 
== See Also ==
 
* [http://www.macosxhints.com/article.php?story=20021114055617124 MacOSX Hints - Automatically using screen in your shell]
 
* [http://www.macosxhints.com/article.php?story=20021114055617124 MacOSX Hints - Automatically using screen in your shell]
* [http://en.gentoo-wiki.com/wiki/Screen#Tab-bar Gentoo Wiki - Using tabs with screen]
+
* [http://en.gentoo-wiki.com/wiki/Screen Gentoo Wiki - Tutorial for screen]
* [http://bbs.archlinux.org/viewtopic.php?id=50647 Arch Forums - Regarding 256 color issue with urxvt]
+
* [https://bbs.archlinux.org/viewtopic.php?id=50647 Arch Forums - Regarding 256 color issue with urxvt]
* [http://bbs.archlinux.org/viewtopic.php?id=55618 Arch Forums - .screenrc configs with screenshots]
+
* [https://bbs.archlinux.org/viewtopic.php?id=55618 Arch Forums - .screenrc configs with screenshots]
* [http://wiki.archlinux.org/index.php/Tmux Arch Wiki - tmux, another multiplexer]
+
* [[tmux]], another multiplexer
 +
* [[Ratpoison|Ratpoison - A window manager based on gnu screen]]
 +
* [[Xpra|Xpra - An utility to detach/reattach X programs, in a way similar as screen does for command line based programs]]

Revision as of 14:10, 6 May 2013

GNU Screen is a wrapper that allows separation between the text program and the shell from which it was launched. This allows the user to, for example, start a text program in a terminal in X, kill X, and continue to interact with the program. Here are a couple of tips and tricks you may be interested in.

Installation

GNU Screen can be installed using the screen package found in the official repositories.

Usage

Commands are entered pressing Template:Keypress and then the key binding.

Common Commands

Tips and tricks

Change the escape key

The escape key can be changed with the escape option in ~/.screenrc. For example:

escape ``

sets the escape key to Template:Keypress.

Start at window 1

By default, the first screen window is 0. If you'd rather never have a window 0 and start instead with 1, add the following lines on your configuration:

$HOME/.screenrc
bind c screen 1
bind ^c screen 1
bind 0 select 10                                                            
screen 1

Nested Screen Sessions

It is possible to get stuck in a nested screen session. A common scenario: you start an ssh session from within a screen session. Within the ssh session, you start screen. By default, the outer screen session that was launched first responds to Template:Keypress commands. To send a command to the inner screen session, use Template:Keypress Template:Keypress, followed by your command. For example:

Use 256 colors

By default, screen uses an 8-color terminal emulator. Use the following line to enable more colors, which is useful if you are using a more-capable terminal emulator:

$HOME/.screenrc
term screen-256color

If this fails to render 256 colors in xterm, try the following instead:

$HOME/.screenrc
attrcolor b ".I"    # allow bold colors - necessary for some reason
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'   # tell screen how to set colors. AB = background, AF=foreground
defbce on    # use current bg color for erased chars

Use 256 Colors with Rxvt-Unicode (urxvt)

If you are using rxvt-unicode from the official repositories, you may need to add this line in your ~/.screenrc to enable 256 colors while in screen.

$HOME/.screenrc
terminfo rxvt-unicode 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'

Informative statusbar

The default statusbar may be a little lacking. You may find this one more helpful:

$HOME/.screenrc
hardstatus off
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W} %c %{g}]'

Turn welcome message off

$HOME/.screenrc
startup_message off

Turn your hardstatus line into a dynamic urxvt|xterm|aterm window title

This one is pretty simple; just switch your current hardstatus line into a caption line with notification, and edit accordingly:

$HOME/.screenrc
backtick 1 5 5 true
termcapinfo rxvt* 'hs:ts=\E]2;:fs=\007:ds=\E]2;\007'
hardstatus string "screen (%n: %t)"
caption string "%{= kw}%Y-%m-%d;%c %{= kw}%-Lw%{= kG}%{+b}[%n %t]%{-b}%{= kw}%+Lw%1`"
caption always

This will give you something like screen (0 bash) in the title of your terminal emulator. The caption supplies the date, current time, and colorizes your screen window collection.

Use X scrolling mechanism

The scroll buffer of GNU Screen can be accessed with Template:Keypress Template:Keypress. However, this is very inconvenient. To use the scroll bar of e.g. xterm or konsole, add the following line:

$HOME/.screenrc
termcapinfo xterm* ti@:te@

Attatch an existing running program to screen

If you started a program outside screen, but now you would like it to be inside, you can use reptyr to reparent the process from it's current tty to one inside screen.

Install the package reptyr from the Official Repositories.

Get the PID of the process (you can use ps ax for that). Now just enter the PID as argument to reptyr inside a screen window.

$ reptyr <pid>

Add a GRUB entry to boot into Screen

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: Initscripts is deprecated, and the use of runlevels as well. Also, this instructions are for legacy GRUB (Discuss in Talk:GNU Screen#)

If you mostly use X but occasionally want to run a Screen-as-window-manager session, here is one way to do it by adding a GRUB entry for Screen on a virtual console (text terminal).

GRUB allows you to designate what runlevel you want so we will use runlevel 4 for this purpose. Clone an appropriate GRUB entry and add a 4 to the kernel boot parameters list, like so:

# (0) Arch Linux
title  Arch Linux Screen
root   (hd0,2)
kernel /vmlinuz-linux root=/dev/disk/your_disk ro acpi_no_auto_ssdt irqpoll 4
initrd /initramfs-linux.img

Add some entries to /etc/inittab to indicate what should happen on runlevel 4, substituting your user name for <user>:

# GNU Screen on runlevel 4
scr2:4:respawn:/sbin/mingetty --autologin <user> tty1 linux

The above line uses mingetty to automatically login some user to a virtual console on startup. You will need to install the mingetty package from the official repositories. The inittab line segments are separated by colons. The first part (scr*) is simply an id. The second part is the runlevel: This should only happen on runlevel 4 (which is not used in any default setup - 3 is by default for a tty login and 5 is for X). 'Respawn' causes init to repeat the command (i.e. autologin) if the user logs out. We will need to see that nothing else happens on virtual console 1 when we use runlevel 4, so remove 4 from the the first of the agetty lines:

c1:235:respawn:/sbin/agetty -8 38400 vc/1 linux

Once we are logged in, we want to ensure that screen is started. Add the following to the end of your ~/.bash_profile:

vico="$(tty | grep -oE ....$)"
case "$vico" in
   tty1) TERM=screen; exec /usr/bin/screen -R arch;;
esac

This checks for the current runlevel and will launch a screen session immediately after the automatic login if the runlevel is 4.

This can also be adapted to run screen on a virtual console next to X, simply checking for the current tty instead of the current runlevel. This checks to see if we are on virtual console 3:

vico="$(tty | grep -oE ....$)"
case "$vico" in
  vc/3) TERM=screen; exec /usr/bin/screen;;
esac

Set inittab/mingetty to automatically log in to vc/3 on runlevel 5 and you are set.

Setting a different bash prompt while in screen

If you want a different bash prompt when in a screen session, add the following to your .bashrc:

if [ -z $STY ]
then
        PS1="YOUR REGULAR PROMPT"
else  
        PS1="YOUR SCREEN PROMPT"
fi

[1]

Troubleshooting

Fix Midnight Commander hard hang when starting in screen

In some cases (need deeper inspection) old gpm bug gets alive. So, then you try to run mc inside screen, you get a frozen screen window. Try to kill gpm daemon before starting mc and/or disable it in /etc/rc.conf.

Fix for residual editor text

When you open a text editor like nano in screen and then close it, the text may stay visible in your terminal. To fix this, put the following:

$HOME/.screenrc
altscreen on

See Also