, , ,

There are also a number of tutorials on how to keep environment variables set in screen sessions. Why does this matter? Because SSH relies on it – for SSH agent operation, as well as X forwarding. Thus, each of the articles solve a slightly different problem, but it all comes out to the same thing: getting the environment variables right.

Many of the tutorials start with this problem: one starts ssh-agent, then screen: now how do the sessions maintain the proper environment variables? This article by Charles Fry shows a way to craft a screen initialization script with the proper variables. This article suggests using a screen “wrapper”: run screen first, then ssh-agent, the screen again. The inner screen session then becomes the main session, and the outter session mainly holds the results of the ssh-agent run.

Some tutorials handle a different problem: one starts ssh-agent, then connects to another machine with ssh – then runs screen after that. That screen session will become “disconnected” from the ssh-agent forwarding scheme once you exit and connect to it from another machine. The environment variables are no longer valid. The basic solution is to overwrite the session environment variables with the current (and correct) version. Samat Jain has an article on this, and Sam Rowe also has an interesting article at deadman.org about the same thing.

On a different note, there is an excellent tutorial and overview of GNU screen at polishlinux.org. While it is from July of 2007, it remains up to date – I just don’t know why I haven’t seen it until now. If you haven’t started using screen, this is a good place to begin.

Of course, there is my book GNU Screen: A Comprehensive Introduction.