Warning: xterm-related technical information follows.

If you are using X and the xterm terminal emulator, you can use the "secure keyboard" option to temporarily ensure all keyboard input is sent only to the xterm. This not only stops unexpected pop-ups from getting your password accidentally, but also foils any trojan programs that might be snooping on you.

Usually this is set up on the "Main Options" menu, accessed by holding control and pressing and holding the left mouse button, inside the xterm window. The "secure" function is a toggle. It will reverse the video when it has successfully activated — if this does not happen then you are not secure!

A really handy tip is to bind this to a button on your keyboard you don't normally use in an xterm (e.g., F12). Then, hit that key every time before you type a password, and then whack it again when you've finished typing it.

To set this up, you need to add the following X resource setting. Normally you can just put this in your ~/.Xresources or equivalent file, or you can load it by hand with xrdb -merge:

xterm*VT100.Translations: #override F12: secure()

The list of keys you can use and their names can be found in /usr/include/X11/keysymdef.h, just strip off the XK_ part of the name.

Note: will only take effect on new xterms started after you load the resource setting.