Every so often our cable internet (Time Warner Road Runner) will go “out.” Only it’s not really “out”: the cable modem’s internet connection is still on and I can ping IP addresses. What’s really happening is Road Runner’s DNS servers stop responding to DNS queries. This doesn’t happen very often, and it is usually resolved in a few minutes, but that’s too long when I’m trying to work.
The solution: OpenDNS. These guys run a top-notch DNS service. It’s free, reliable, fast, and supposedly safer. The Getting Started page has detailed instructions for using OpenDNS’s servers in place of your ISP’s servers.
In 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
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:
ssh -t email@example.com "screen -R"
I’ve added two items to the script:
-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.
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
I spend pretty much all day connected to remote machines via ssh. It’s key to my work and losing that connection for any reason is a big productivity vacuum. Lately I’ve been having some connection problems, which has prompted me to streamline how I connect to my remote machines. ssh-agent and screen are great tools for improving my connectivity productivity. I’ll talk about ssh-agent in this post, and screen in the next one.
ssh-agent enables almost-password-free* logins to your remote machines. This is accomplished via SSH keys. You basically generate an encryption key pair on your local machine and then copy your public key out to each user on each remote machine. ssh-agent runs in the background on your local machine. You add your identity to the ssh-agent and supply a passphrase. As long as you keep your session (X session/login session) open and ssh-agent running, you won’t need to enter a password when ssh’ing to a remote machine. This can significantly reduce your password typing during a day. Here’s how I set it up:
$ssh-keygen -t rsa
Enter a passphrase when asked and remember it. Two key files are generated: your private key and your public key.
#key files generated on your local machine:
You will need to copy the contents of your public key file (id_rsa.pub) to each remote user’s authorized_keys file. If this file doesn’t exist, create it.
#on each remote machine, copy your public key into this file:
Now make sure that ssh-agent is running on your local machine. You want to run ssh-agent for your login or X session. I’m using Gnome and GDM on Gentoo, and ssh-agent is already setup for each session. If you need to add it manually, see this page: http://www.phy.bnl.gov/computing/gateway/ssh-agent.html
Now add your ID to the running ssh-agent:
Enter passphrase for /home/username/.ssh/id_rsa:
Identity added: /home/username/.ssh/id_rsa (/home/username/.ssh/id_rsa)
You can now SSH into your remote machines without having to enter a password. Try it!
*So, the only password you must enter is the passphrase for the identity you’ve created for ssh-agent. You will need to re-add this identity everytime ssh-agent is restarted (e.g., when you close your session).
In order to further streamline the password-entering, this script checks whether or not the ID has already been added and runs ssh-add if not:
# If no ID has been added to ssh-agent, then run ssh-add.
if [ -n "`ssh-add -l | grep has\ no\ identities`" ]; then
Then, each of my SSH connections gets its own launch script that looks like this:
I got the ID-checking script from here:
Also read my post about how I use GNU screen.
My beloved Linksys WRT54G (version 1.0) wireless router gave up the ghost this past week (I think because of a power issue). I attempted to debrick it, but no dice.
I went out to Wally World (Wal-Mart) and picked up the latest model without doing too much research. Mistake. Version 5 is piece of junk! It keeps dropping my SSH connections every few minutes and sometimes completely freezes up and I have to unplug and re-plug to fix it. Apparently, version 5 of the WRT54G contains vxWorks firmware instead of the Linux firmware found on older models.
The solution is to buy the Linux enthusiast’s version of the router, the WRT54GL, at a premium cost: ~$10 more. I can’t work with version 5, so I’ve ordered a WRT54GL and it should be here today or tomorrow.
Linksys: Did you really save that much more money by switching to vxWorks (+ less RAM)? What has this move cost you in terms of reputation and support costs on such a piece of junk?
UPDATE 04/05/06:I got the WRT54GL, and as expected, it ROCKS! I swiftly voided my warranty by putting DD-WRT on it. If you decide to do this, read the DD-WRT documentation carefully.
Every once in a while I do something really, really stupid. Like, say, for instance, delete a whole directory of very important code that I’m working on and my last backup is a couple of weeks old (because of a server move and my failure to re-setup my cron backup). How did this happen? Well, for one, I was coding at about 5:30 a.m. before my caffeine had set in, and, secondly, I was rm -rf’ing with tab-completion. Almost instantly after I pressed Enter I realized what I had done. Tragedy. Or so I thought…
In Linux, you can undelete files if you are using the ext2 file system. A very handy tool called debugfs allows you to list files marked as deleted. I’m using the ext3 file system (ext2′s successor), so I thought the debugfs solution would work. Unfortunately, ext3 actually zeros out the block pointer (the pointer to the file’s data), so reconstructing the file becomes impossible with debugfs.
So, what to do? I had seen some mailing list posts refering to ‘grepping’ the data from the disk drive. Most everything I lost was code (specifically, Ruby). I attempted to use grep to search my hard disk device (/dev/sda7 in my case), but grep kept erroring out with “memory exhausted” errors. Hrrm.
A rethink of the problem led me to the ‘strings’ program, which extracts text from files, stdin, or even a disk device. I dumped all text from the disk partition to a text file like so:
#strings /dev/sda7 > /path/to/big_text_file
Note: It is probably a good idea to put the big text file on a separate partition. Otherwise, you risk writing over some of your deleted files on the partition you are attempting to recover from.
I was now able to open the big_text_file in vim and recover all of my deleted code by searching for particular code snippets. It’s not ideal, but I was able to recover everything. Instead of losing several days worth of work, I only lost a couple of hours.
And, of course, my backup is re-setup.