Philip J. Guo - Personal Home Page
Main Menu

Computer Quick Tips

by Philip Guo (philip@pgbovine.net)

This page is a compilation of useful computer-related tips that I have collected both from others and from my own experiences.

Contents:


UNIX command-line tools

You can accomplish quite a lot at the UNIX command line without writing a single line of code. Here are some useful commands:

CVS

Here are some useful CVS commands:

ssh - passwordless, agents, forwarding, proxys

Here are some neat ssh tricks to help improve your productivity by allowing you to not type in a password nearly as often. When I first learned to use ssh to remotely login to computers at work, I simply typed in my password every time I logged in. This grew annoying after a while. For example, whenever I used cvs over ssh, I would have to type in my password every time I performed a cvs operation.

Then I learned to use ssh-agent to authenticate using public/private keys instead of using a password. There are many guides on the Internet for how to do this, so I'll just summarize:

  1. On your personal computer, run ssh-keygen -t dsa to generate a public/private key pair in your ~/.ssh/ directory. Enter a passphrase (which is really just a password) to protect your key.
  2. In your ~/.ssh/ directory, id_dsa is your private key. Never move this key anywhere off of your personal computer. Nobody except for you should have access to this key.
  3. id_dsa.pub is your public key. You should copy this key to all the remote computers which you want to log into. Do so by logging into your home directory on each remote computer, and appending your public key (which should fit in ONE long line) to the end of the ~/.ssh/authorized_keys file (create one if it doesn't already exist) on each computer you want to log into. ssh is very picky about file permissions in order to work properly with keys, so do a chmod 644 .ssh/authorized_keys and chmod 700 .ssh on remote machines to set the proper permissions. (Better yet, use the ssh-copy-id program to handle all of this automatically!)
  4. Now when you log into one of the remote computers on which you've installed your public key, ssh will prompt you for your passphrase (instead of your regular password). You should be able to login as usual. Now you're probably asking yourself, "uhhh okay, I still have to type in a password every time, except now it's called a passphrase instead ... hardly an improvement."
  5. Now here comes the magic. Run:
      eval `ssh-agent -s`
      ssh-add
    
    It will prompt you for your passphrase. Enter it once, and the ssh-agent saves it. Try logging into your remote computer now. If all works out, then you shouldn't have to type in your password! You only need to run ssh-add once for every login session, so you have to type in your password at most once per login to your personal computer instead of during every login attempt to the remote computer.

The devil's always in the details, so please search for more detailed guides to passwordless ssh login to get the kinks worked out for your particular OS. On Mac OS X, I use SSHKeychain to manage my keys so that I only need to type in my password once for every login session.

Okay, now say there are a few computers at work that I want to log into, and I want to ssh BETWEEN those computers without entering in my password. Let's say I have a home computer named home and 3 work computers, alpha.work.net, beta.work.net, and gamma.work.net. I have my public key installed in the ~/.ssh/authorized_keys files in all 3 work computers. Using ssh-agent, I can log from home to alpha.work.net, beta.work.net, and gamma.work.net with no password typing. That's fine and dandy, but what if after I log into alpha.work.net, I want to then log into beta.work.net, or to log from gamma.work.net to alpha.work.net, etc.? That is, what if I want to connect from home to one of my work computers, then seamlessly log into my other work computers without re-typing my password? I could place my private key on all those computers and setup ssh-agent, but I still need to type in my password at least once every time I log in (since it starts a brand new login session). Also, it's not safe to put your private key on a remote computer, even if you make it only readable by yourself, since the root user can always snoop on your files :0

ssh agent forwarding is a better way to achieve this goal, without the need to copy your private key off of your home computer or to re-type your password. To activate agent forwarding, put the following line in the ~/.ssh/config file on all the computers (create one if it doesn't already exist):

  ForwardAgent yes

This will allow you the ssh-agent to 'forward' your saved password through all of the computers, so that you can type in your password once on your home computer at the beginning of your session and seamlessly log into and, more importantly, BETWEEN all of your work computers without having to re-type your password.

One final trick before we part ways ... let's say that only one computer at work is publicly accessible. Let's call that alpha.work.net. Thus, it's possible login from home using:

  ssh alpha.work.net

but it's not possible to log into beta.work.net or gamma.work.net using the respective commands since they are not publicly accessible:

  ssh beta.work.net
  ssh gamma.work.net

For security reasons, many workplaces only allow you to log into a limited number of 'gateway' computers from the Internet, and the rest of the computers are only accessible from within the local network. It's annoying to always have to first log into alpha.work.net from home and then manually log into, say, beta.work.net. To overcome this problem, we will use ssh proxy commands. Add the following lines to ~/.ssh/config on your home computer:

  Host beta.work.net
    ProxyCommand ssh -q -a -x alpha.work.net nc -w 1 %h 22

  Host gamma.work.net
    ProxyCommand ssh -q -a -x alpha.work.net nc -w 1 %h 22

These lines set up alpha.work.net as an intermediate proxy to connect to beta.work.net and gamma.work.net. Now you should be able to run:

  ssh beta.work.net
  ssh gamma.work.net

and login fine ... as you might have guessed, you are actually first logging into alpha.work.net and then logging into your desired work computer, but ssh proxy commands handle this transparently. Another benefit besides convenience is that you can now use ssh-dependent tools such as scp, sftp, unison, and sshfs to directly connect your home computer to a work computer that's not ordinarily publicly accessible. Hot!

XEmacs

I use XEmacs as my main text editor for writing programs, HTML, LaTeX, and just about anything which requires text editing. I find that it's a bit more integrated with modern GUI's than traditional GNU Emacs, and it has a few keyboard shortcuts that aren't build into GNU Emacs. I use XEmacs both on Windows and UNIX. Here are some commands that I use on a regular basis:


Programming in general

This is where I put general programming tips which are fairly language-independent.

Basic BASH shell programming

There are many comprehensive guides to BASH shell programming (such as this one), but they often provide too much overwhelming detail for casual script writers (like me) who just want to get some quick and dirty work done. Here are some quick tips:

C programming in UNIX


Converting from HTML to XHTML

XHTML is considered by many to be the desired language for the future of the web. It is quite similar to HTML except that it has much stricter standards for what is allowed to be a legal XHTML document. Think of XHTML as "proper, non-sloppy HTML" or the HTML that results after repeated nitpicking to ensure 'good form'. One great advantage of XHTML over HTML is that an XHTML document can be treated like XML, which allows a plethora of XML-based tools (such as parsers for various programming languages and especially the XSLT transform language) to operate seamlessly on it. Web browsers are usually pretty lenient when parsing HTML so that you can write fairly sloppy HTML and still have it display correctly. However, the standards for XHTML are much more strict, so if you abide by these standards, then your pages will be more likely to display correctly on current and future browsers, but more importantly for nerds, be able to be treated like XML!

My regular webpages on this site are done in plain 'ole HTML (I haven't had the motivation to convert them yet), but one day I decided to convert my People Photo Gallery site from HTML to XHTML because I wanted to try to use it with XSLT (which only works on XML documents). It was a pretty painful 3-hour ordeal to clean-up all of my HTML so that it was also legal XHTML. I mainly

followed the tips in this guide and did lots of trial & error until I got my XHTML gallery working just like how my existing HTML gallery worked.

Instead of regurgitating the contents of that guide, I will now list some useful tips that I had to learn the hard way (so hopefully you won't have to!):


Backing up your data

Backups. It's something which everyone knows that they should do, but in reality, few people do it. Why don't people back up their data more often? Often times, it's because they don't know what's the best way to do so. It's unfortunate that the people who don't make regular backups are the ones who are more likely to have their computers crash (due to general inexperience), whereas the computer experts who backup neurotically rarely have to deal with crashes.

Many people fear backups because they think that they have too much stuff to back up. From my experience, the actual amount of data that you really need to back up is fairly small. Here is what I would back up: everything which you personally created yourself or cannot otherwise be easily replaced. This includes your documents, digital photographs, email, artwork, etc..., but NOT your downloaded music, movies, and programs. Think about what takes up most of the space on your computer: music, movies, games, and other stuff that can be easily replaced. Backup only those things that cannot be easily replaced, and you'll find that they actually don't take up much room at all.

Here are some common methods that I've used to back up my data, listed in order of complexity. Remember to choose a method which you are comfortable using on a regular basis, because no matter how good a backup method is, it's useless if you don't use it!

The cheapest way to get foot pedals

Foot pedals are fairly simple devices: they are switches that you step on to function as Ctrl, Alt, or other modifier keys on your keyboard. Therefore, instead of holding down those keys on the keyboard while trying to type commands, you can simply press down with your foot. This helps to alleviate strain on your hands, especially when using programs like Emacs which rely heavily on 'chords' where you must hold down a modifier key while pressing other keys.

To my chagrin, foot pedals usually cost more than $100, which is way too expensive for such simple electro-mechanical devices. It is not too difficult to hack up your own foot pedal (Derek Rayside's web-site shows you how), but I'm not too handy with 'real-world tools', so I thought of an even easier way to get foot pedals:

Put a second keyboard on the floor and use it as a foot pedal. I am not joking; it really works!!! Windows XP and the Linux distros I've used (Ubuntu, Debian) allow you to plug in multiple keyboards into the PS/2 and USB ports and accepts input from any of them. Simply obtain a second keyboard, put it on the floor, and put your two big toes on top of modifier keys (I use my left toe for the left Alt and right toe for the right Ctrl), and gently tap down on the keys to emulate foot pedals. Of course, this isn't as comfortable as being able to mash your entire foot down on a pedal, but it's a good start. If you really want, you could hack up your secondary keyboard to remove the rest of the keys and enlarge the modifier keys to give yourself larger targets for foot mashing. (Unfortunately, this hack doesn't work on Mac OS X ... I guess they're just too 'smart' about handling inputs from multiple keyboards.)


Keeping Windows XP free of viruses and spyware

Up until Summer 2005, I used Windows XP most of the time and switched to UNIX mainly to do programming for work. Many people have complained how their Windows machines are filled with viruses and spyware, but I have found through experience that you can greatly decrease the chances of your computer getting screwed up by following a few simple rules:

Great free programs for Windows XP

Do your Mac friends make fun of you because you are a chump who can't run pretty iPhoto? Do your Linux haCKeRZ friends make fun of you for being a n00b who can't get the latest obscure command-line tools? Are you a Windows user who finds yourself resorting to shady pirated burned CD's that you got from a friend of a friend? Well, believe it or not, you can actually get a good deal of high-quality free software for Windows XP without resorting to software piracy. The programs listed below should handle most of your daily computing tasks, and all come totally for free, no strings (or advertisements) attached!


Created: 2005-05-11
Last modified: 2007-01-20