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 terminali.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
Multiple views of a terminali.e. simultaneously connecting from another place.
To attach: screen -x
Multiple users of a terminalFor 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/screenThen user1 can share their session on host as follows:
screen -S shared-sessionCtrla :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 terminalFor 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 fedorauser1 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:
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.