Wednesday, May 14, 2008

How to Set up Password-less SSH'ing?

Create RSA key pairs:
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/joe/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/joe/.ssh/id_rsa.
Your public key has been saved in /home/joe/.ssh/
The key fingerprint is:
00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 joe@mycomputer
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
Copy your public key to host server:
$ scp ~/.ssh/
Then, log into your host server and create/append the public key to a file named, authorized_keys:
$ cat ~/.ssh/ >> ~/.ssh/authorized_keys
$ chmod go-w ~/. ~/.ssh/authorized_keys
$ chmod go-rwx ~/.ssh
NOW, logout and log back in. You won't be asked for the password again!

Tuesday, May 6, 2008

Bash Script Exit Codes

Exit Code NumberMeaningExampleComments
1catchall for general errorslet "var1 = 1/0"miscellaneous errors, such as "divide by zero"
2misuse of shell builtins, according to Bash documentationSeldom seen, usually defaults to exit code 1
126command invoked cannot executepermission problem or command is not an executable
127"command not found"possible problem with $PATH or a typo
128invalid argument to exitexit 3.14159exit takes only integer args in the range 0 - 255
128+nfatal error signal "n"kill -9 $PPID of script$? returns 137 (128 + 9)
130script terminated by Control-CControl-C is fatal error signal 2, (130 = 128 + 2, see above)
255*exit status out of rangeexit -1exit takes only integer args in the range 0 - 255

According to the table, exit codes 1 - 2, 126 - 165, and 255 [1] have special meanings, and should therefore be avoided as user-specified exit parameters. Ending a script with exit 127 would certainly cause confusion when troubleshooting (is the error a "command not found" or a user-defined one?). However, many scripts use anexit 1 as a general bailout upon error. Since exit code 1 signifies so many possible errors, this might not add any additional ambiguity, but, on the other hand, it probably would not be very informative either.
There has been an attempt to systematize exit status numbers (see /usr/include/sysexits.h), but this is intended for C and C++ programmers. A similar standard for scripting might be appropriate. The author of this document proposes restricting user-defined exit codes to the range 64 - 113 (in addition to 0, for success), to conform with the C/C++ standard. This would allot 50 valid codes, and make troubleshooting scripts more straightforward.

Friday, May 2, 2008

How to Change the Thumbnail Picture of a Folder in Windows 7 and Vista?

In the Windows Explorer window, when user chooses to display the files and folders listing in Extra Large Icons, Large Icons, Medium Icons and Tiles view, Windows 7/Vista can show a preview thumbnail on the icons of folders itself using content inside the folders, normally image and photo or file type icon if there is no graphic file inside the folder.

The thumbnail preview picture on folders’ icon listing in Windows Explorer window allows user to have a quick yet comprehensive glance about the file contents that may contains inside the folders. However, sometimes, the thumbnail preview image is not the one that user wants. In this case, user can customize or self define a picture to be used, placed and showed on the folder icon.
  1. In Windows Explorer, at folder parent level, right click on the folder that want to change its preview image on folder icon, and then select Properties.
  2. Click on Customize tab.
  3. Under Folder pictures section, click on Choose File button.
  4. In “Browse” dialog box appears, select an image file to represent the folder and to show on the folder icon when viewing directory listing in supported views, and click Open.
  5. The selected picture will be used as thumbnail preview image on folder icon with immediate effect.
  6. To revert the setting (remove the user-set folder picture, click on Restore Default button instead.

Alternative Method

  1. Copy an image in .JPG or .GIF format that user want to use as folder picture into the folder itself.
  2. Rename the picture file name to Folder. For example, Picture1.jpg should be renamed to Folder.jpg and Picture1.gif should be renamed to Folder.gif.
  3. Optionally, set the folder picture file (Folder.img) with hidden attribute to prevent it from displaying when listing folder’s contents.
  4. To revert and restore the original Windows 7/Vista automatic assigned folder pictures, just delete the Folder.img file.
  5. Note that for alternative method, .BMP and .PNG image formats is not supported.