Macro 32 Ramblings

Mind Archive

Screen Shortcuts

Note for nested screen sessions, use "Ctrl+a a" to send commands to the inner screen,
and the standard "Ctrl+a" to send commands to the outer screen.
Key Action Notes
Ctrl+a c new window
Ctrl+a n next window I bind F12 to this
Ctrl+a p previous window I bind F11 to this
Ctrl+a “ select window from list I have window list in the status line
Ctrl+a Ctrl+a previous window viewed
 
Ctrl+a S split terminal horizontally into regions Ctrl+a c to create new window there
Ctrl+a | split terminal vertically into regions Requires screen >= 4.1
Ctrl+a :resize resize region
Ctrl+a :fit fit screen size to new terminal size Ctrl+a F is the same. Do after resizing xterm
Ctrl+a :remove remove region Ctrl+a X is the same
Ctrl+a tab Move to next region
 
Ctrl+a d detach screen from terminal Start screen with -r option to reattach
Ctrl+a A set window title
Ctrl+a x lock session Enter user password to unlock
Ctrl+a [ enter scrollback/copy mode Enter to start and end copy region. Ctrl+a ] to leave this mode
Ctrl+a ] paste buffer Supports pasting between windows
Ctrl+a > write paste buffer to file useful for copying between screens
Ctrl+a < read paste buffer from file useful for pasting between screens
 
Ctrl+a ? show key bindings/command names Note unbound commands only in man page
Ctrl+a : goto screen command prompt up shows last command entered

 

The following scenarios were tested both on Fedora and Ubuntu, but should work on any linux distro at least.

If you want to try these examples out locally, just replace references to “@host” with “@localhost”.
You may also find my screen settings and screen keyboard shortcut reference useful.

 

Reattaching to a terminal

i.e. connecting again from another place or at another time.This is very useful as the managed programs keep running after you detach, even if they produce output, or you logout, or your dial-up hangs for e.g. Note Linux does not native support for reattaching processes to terminals (like VMS), so this is a very useful function indeed, and is a much better/easier solution than using disown or nohup. Of course screen must already be running before any of the managed programs.

To detach: Ctrla d
To reattach: screen -r

Multiple views of a terminal

i.e. simultaneously connecting from another place.To attach: screen -x

screen multi view

Multiple users of a terminal

For security reasons, screen by default is installed so that other users within the system can not attach to your screen sessions. To allow this to be changed one must set screen to run SUID root by doing the following (once):

sudo chmod +s /usr/bin/screen
sudo chmod 755 /var/run/screen

Then user1 can share their session on host as follows:

screen -S shared-session

Ctrla :multiuser on
Ctrla :acladd user2

user2 on host can then connect to the shared session like:

ssh user2@host
screen -x user1/shared-session

Multiple read-only users of a terminal

For example one could give a group of users a demo by setting up read-only access to locked down account. This is an extension to just sharing a screen session, so again screen must run SUID root as described above. Then one could create a locked down “guest” account like:

sudo su -
ln -sf bash /bin/rbash
useradd -s /bin/rbash guest
passwd guest #enter password

echo '
trap "" 2 3 19 #try to stop user getting to shell
clear
echo "Welcome to the demo"
echo "You can enter Ctrl-ad to detach at any time or just close your terminal"
echo "You can message all users by doing, Ctrl-a: wall \"your message\""
echo -n "Press Enter to continue..." && read
screen -x user1/shared-session
exit' > ~guest/.profile
echo '. .profile' >> ~guest/.bash_profile #for fedora

user1 then runs a shared session on host as above and in addition makes guest connections read-only by doing:
Ctrla :aclchg guest -wx “#,?”
Ctrla :aclchg guest +x “colon,wall,detach”

guests then can connect to the read-only demo by just doing:

ssh guest@host

Note user1 can see who has attached and the the size of their terminals with Ctrla : displays. This can be used to tell people to resize their terminals, or user1 can resize their own to the largest acceptable to everyone.

Note also that the settings above allow users to “wall” questions or comments to the group. If one wanted a richer interaction mechanism, then it would be advised that the group logs into a parallel realtime chat sytem, like IRC for example.