productivity tools: screen
software, tech tips April 7th, 2006In my last post, I wrote about setting up ssh-agent to streamline your connectivity to SSH remote hosts. In this post, I'll introduce screen, which I use in conjunction with ssh & ssh-agent to further improve my connectivity productivity.
screen is a console window manager that multiplexes between multiple terminals. If multiplexing was it's only feature, then it would not be anymore useful than any existing multiple-tab terminals available in a GUI environment. What really sets screen apart is its ability to open a screen session, detach that session from your connection, and then reattach it later on. In other words, if I'm using screen, I can completely lose my SSH connection, reconnect, and then reattach to the screen session–putting me right back to where I was previously working before the connection dropped.
You can read more in-depth at Jonathon McPherson's article on screen, but here's a quick run down of GNU Screen commands to get started:
$screen #start screen
$screen -r #reattach to an existing screen process
$screen -R #reattach if possible, or start new session
#within screen:
Ctrl+a, c #create a new window
Ctrl+a, n #switch to next window
Ctrl+a, p #switch to previous window
Ctrl+a, N #switch to Nth window (0-9)
Ctrl+a, " #list windows, choose with arrow keys and Enter
In my previous post, I setup a launch script for each remote SSH connection so that I could ensure that my ID had been added to the ssh-agent. I'm now going to tweak this script to launch screen upon connection to save me the trouble of typing "screen -R" everytime I reconnect:
#!/bin/bash
# ~/bin/sv1
ssh-id-check
ssh -t user@remotemachine.com "screen -R"
I've added two items to the script:
- the ssh -t option is necessary to force the correct terminal type. The excerpt from the GNU screen manual page:
-t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g., when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.
- the "screen -R" command is appended to the ssh command and will execute on the remote machine after connection. The -R option will connect to any existing screen session if possible or open a new one if not.
Now when I lose my SSH connection, I need only type the two or three-letters for my launch script and I'm put right back to where I was before the connection dropped. Nifty!
One additional tip:
If you use xterm and your scrollbar is not working, then put this into your ~/.screenrc file on each of remote machines you're using screen with:
termcapinfo xterm ti@:te@
see this info from the Screen FAQ
Recent Comments