Screen Hijack
2012-09-13
If you've ever tried to take over somebody else's detatched screen sessions, by using the su command to assume their login identity, you've probably seen an error message something like
Cannot open your terminal device /dev/pts/3
This is because your pseudo terminal device is allocated when you login to the session, and remains owned by the user id you logged in, after you've changed your effective uid by su -ing.
You can try and kludge your way around it by chmod -ing your pty device file to make it more arbitrarily readable, but that's ugly and stupid, and needs escalated privileges. A slightly smarter way to work around this is to force a new pseudo terminal for the assumed login session. A really simple way to do this that I've recently discovered is to use the script utility. script is a useful tool intended to preserve a transcription of an interactive terminal session. To do this, it creates a new pty device for the current user id. So you can use it to help you recover a detatched screen by typing this
su - someuser
script /dev/null
screen -r somesession
Passing /dev/null to script just means that the transcript is discarded.