Migrating from Windows XP to Mac OS X, Part 2

Mac OS X No Comments

stevejobsIt has been over a year since I migrated to a Macbook Pro laptop and started using the Mac OS X operating system. Since then, I have learned some useful tips and tricks, which I have shared below.

Using Keyboard Shortcuts

If you can master keyboard shortcuts, you will be able to perform some actions (especially repetitive ones) much faster than using the trackpad.

Enable Tabbing Between All Controls

This will allow you to tab to any control, such as a button, in a window or dialog.

  1. Go to “System Preferences” and Keyboard.
  2. In the “Full Keyboard Access: …” section at the bottom, make sure that the “All controls” radio option is checked.

Strangely, after you tab to a button, some dialogs require you to press the Return key and other dialogs require you to press the Space key in order to “click” the button.

Perform a Screen Capture

Use the following key combinations to perform either a full screenshot or a cropped screenshot:

  • Simultaneously press Apple + Shift + 3 keys to perform a full screenshot.
  • Simultaneously press Apple + Shift + 4 keys to enter cropped screenshot mode, where the cursor becomes a target icon. Click down, without releasing, to pick a corner of the shot and drag to frame the shot (you will see a translucent rectangle). Release to take the cropped screenshot.

The screenshots will appear on your desktop as PNG image files.

Deleting Files

Select one or more files and simultaneously press Apple + Delete keys to delete them. This key combination will also work to delete folders. The deleted files and folders are placed in the waste basket.

Force Quit an Application

If your Mac OS X appears to be frozen due to an unresponsive program, one drastic measure is to kill that program’s process. Simultaneously press Command + Option + Esc keys to open up the “Force Quit Applications” dialog, select the offending application, and click on the “Force Quit” button.

Note: For more details on running applications (in addition to disk, memory, and network usage), you can launch the “Activity Monitor”.

Just for Fun

There are a ton of keyboard shortcuts. You just have to find the ones most useful to you. For example, here’s a fun shortcut: press Fn + Shift + F10 keys to make the current window bright and slowly move to the center, while everything else fades away.

Command Line With Terminal

The Terminal application is equivalent to the Linux shell or the DOS command prompt. For certain activities such as writing scripts or doing development, I prefer to use the command line. So I was very glad that Mac OS X came with the Terminal application. One can open several Terminals and even skin them so they will be partially transparent.

Launch an Application

One can launch a Mac OS X application from the Terminal by issuing the following commands:

  • Run “open [application | file | directory | URL]” to launch a particular application (ex: “/Applications/TextEdit.app”), open a file with its default associated application, open a directory using Finder, or browse to a URL using the default browser respectively.
  • Run “open -e [file]” to open a file with the TextEdit application.
  • Run “open -a [application] [file]” to open a file using the specified application.

Debug the Wireless Network

Mac OS X comes with a nifty command line wireless utility called airport. To enable easy access to it, run the following to put it in the command line’s search path:

sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport

Once you have run the above, you can now issue the following commands:

  • Run “airport -I” to see the current wireless status, what SSID you are connected to and the strength of the signal. Note that some of this info is also shown if you hold down Option key while clicking on the Airport status icon in the top menu bar (on the right-hand side).
  • Run “airport -s” to scan the wireless broadcast space.
  • Run “airport -z” to disassociate from any wireless network.

Some other useful commands are:

  • Run “ifconfig en1” to see your machine’s assigned IP address on the wireless network.
  • Run “dscacheutil -flushcache” to flush the DNS cache.

Where’s My CD?

To access another partition or a CD using Terminal, change to the “/Volumes” directory.

Reset Your Admin Password

If you ever forget your administrative password, there are two easy methods to reset the password. One requires the Mac OS X Install CD and the other does not.

Require the Mac OS X Install CD

First method is to boot from the Mac OS X Install CD and run the reset password application.

  1. Insert the Mac OS X Install CD and restart the Mac.
  2. Hold the “C” key on startup to boot from the CD.
  3. Once the specialized Mac OS X operating system on the CD is booted, go to menu “Utilities->Password Reset”.
  4. Select the Mac OS X hard drive.
  5. Select your username and input the new password.
  6. Restart the Mac.

Don’t Require Mac OS X Install CD

Second method uses single user mode and does not require the Mac OS X Install CD.

  1. Restart the Mac.
  2. On startup, hold the Command + S keys down to boot into single user mode.
  3. Once you have Terminal access, input the following commands to reset your password:
    mount -uw /
    ls /Users
    passwd [your_username]
    shutdown -r now

    The second command will show the list of users, one of which will be your username.

  4. Alternatively, if you wish to have Mac OS X prompt you to create a new administrative user, run the following command instead of the “passwd [your_username]”:
    rm /var/db/.AppleSetupDone

    Deleting the .AppleSetupDone file will cause Mac OS X to re-run the setup wizard on bootup, which will prompt you to create a new user account with administrative permission. You can then run “System Preferences->Accounts” to reset any user’s password.

Note: Did you know that Mac OS X, like Windows, has a Safe Mode? If you ever need it, just hold the Shift key on bootup to go into Safe Mode.

Boot Camp for the Schizophrenic

Boot Camp comes with Mac OS X and allows you to dual-boot into either Mac OS X or Windows. It is very easy to setup as long as you have an official Windows installation CD with product key. The only decision you have to make is how much space to allocate to Windows; I recommend 32GB or more for Windows 7 to allow space for applications.

Install Windows

Run “Boot Camp Assistant” and follow the directions.

  • The Windows Support Software can be considered Windows drivers for Mac hardware such as video cards, trackpad, etc. I consider it a requirement, otherwise Windows would not perform well on the Mac.
  • For the “Download Windows Support Software” page, I selected the second option since I had the Mac OS X Installation CD. I did try the first option “Download the Windows support software…” on another Macbook but it failed after several minutes; maybe you will have better luck if you use this option.
  • Per the instructions, insert the Windows installation CD and start the Boot Camp installation.
  • Note: I recommend using an official, unmodified Windows CD. I tried this with a customized, no interaction Windows Install CD and its custom installation script repartitioned the whole drive as a Windows partition (thereby destroying the Mac OS X partition). To recover, I had to reinstall the Mac OS X operating system from scratch.

Configure Windows

Once Boot Camp is installed, on startup, just hold the Option key down and you will be presented with a menu to select either Mac OS X or Windows to boot into. When you are in Windows, insert the Mac OS X Install CD to install the necessary Apple Windows drivers. Once installed, you will see a Boot Camp icon in the bottom-right dock which will allow you to configure the Trackpad, which OS to boot by default, etc.

Mac Keyboards Are Strange!

You will need to either get used to using Windows with the Mac keyboard or alternatively, to remap the Mac keys to match Windows.

Emacs The Way You Want It

Mac OS X comes with a command line version of Emacs. However, I’ve gotten used to GNU Emacs on Windows and wanted the same on the Mac OS X. Here’s how to install GNU Emacs on your Mac:

  1. Download the latest GNU Emacs for Mac OS X.
  2. Open the disk image and copy Emacs.app to the “/Applications” folder.
  3. You can launch GNU Emacs from the command line using “open -a /Applications/Emacs.app [file]”.

Customize Emacs

If you want to customize Emacs to disable the startup splash screen and enable mouse scrolling, create a “~/.emacs” file with the following content:

;;Prevent startup splash screen
(setq inhibit-splash-screen t)

;;Increase width to 120 chars
(add-to-list 'default-frame-alist (cons 'width 120))

;;Set tab to be displayed as 4 spaces, not the default 8
(setq-default tab-width 4)

;;Enable wheelmouse support
(require 'mwheel)

;;Define the mouse scroll wheel
(defun up-slightly () (interactive) (scroll-up 5))
(defun down-slightly () (interactive) (scroll-down 5))
(global-set-key [mouse-4] 'down-slightly)
(global-set-key [mouse-5] 'up-slightly)

;;Support for scrolling (two finger scrolling is double-wheel-up/down)
(global-set-key [wheel-down] 'up-slightly)
(global-set-key [wheel-up] 'down-slightly)
(global-set-key [double-wheel-down] 'up-slightly)
(global-set-key [double-wheel-up] 'down-slightly)
(global-set-key [triple-wheel-down] 'up-slightly)
(global-set-key [triple-wheel-up] 'down-slightly)

Restart Emacs for the changes to take effect.

Remove Windows Return Characters

Files from Windows may contain return characters which show up as visually distracting ^M characters in Emacs. Worse, the Windows return characters inside a bash script file will cause errors on execution. To remove the Windows return characters, open the file in Emacs and perform one of these two methods:

  1. Type “Esc-x set-buffer-file-coding-system”, Enter key, “unix”, Enter key to switch the format to Unix (from Windows).
  2. Type “Esc-x replace-string Ctrl-q Ctrl-m” and Enter key to replace the Windows return characters with nothing. The Ctrl-q will allow you to type control characters into the input buffer, such as Ctrl-m for the Windows return character.

Miscellaneous

This is the dumping ground for random, but possibly useful tips.

VMWare Fusion

When using VMWare Fusion running Windows, you will need to add Fn to the normal Windows keyboard shortcuts. For example:

  • Use Fn + Control + Option + Delete keys to issue a Windows Ctrl-Alt-Delete command.
  • Use Fn + Delete to issue a Windows Delete command.

Firefox

To run Firefox in 32bit mode by default (so some legacy plugins can work):

  1. Go to /Application and select the Firefox icon.
  2. Left-click and select “Get Info” on the Firefox application.
  3. Check the “Open in 32-bit mode” box.

Did you know that you can issue commands in the Firefox address bar? Try the following:

  • Input “about:blank” to get a blank page. (You can also set this as the home page.)
  • Input “about:sessionrestore” to load the tabs that were opened in the previous session. Try using this if Firefox complains that it is unable to recover your saved tabs on startup.
  • Input “about:plugins” to see a description of all the installed plugins.

The above will work in Firefox running on all supported operating systems.

Hopefully all the tips here will help you to enjoy your own Mac migration.

No Comments

Import Movies and TV Shows to Your Apple iPad

Audio Visual, Mobile Devices No Comments

Have you ever imported movies and TV show episodes into your Apple iPad and have them show up as generic videos, not movies or TV shows? Worse, these videos show up without a preview image, just a totally black square? And are the episodes nicely grouped under the TV show’s name? Finally, when you play a movie, can you skip to later chapters?

ipad-indiajonesWell, I have had all of the above problems until I discovered Subler. Subler is available only for Mac OS X. It is used to add meta-info to the movie or TV episode files so they will show up in iTunes and iPad correctly as movies or TV shows. In addition, Subler supports adding chapters, subtitles, and secondary audio tracks (like for other languages). Below are my notes on how I used Subler.

Before anything else, you will need to convert your movie or TV episode into the iPad supported format (usually an MPEG4 file ending in .m4v or .mp4 extension). There are several resources on the Internet about how to do the conversion. Here is a nice tutorial using the free Handbrake tool to convert a movie DVD. If you use this tutorial, before importing the movie into iTunes, make sure to run Subler on it to add a preview image and chapters.

Apple iPad Supported Formats

A quick google search identifies that the iPad supports the following video formats:

  • H.264 video (up to 720p 1280×720, 30 frames per second) with AAC audio (main profile level 3.1 with AAC-LC audio up to 160 Kbps, 48kHz, stereo) in .m4v, .mp4, and .mov file formats.
  • MPEG-4 video (up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second) and AAC audio (simple profile with AAC-LC audio up to 160 Kbps, 48kHz, stereo) in .m4v, .mp4, and .mov file formats.
  • Motion JPEG (M-JPEG) video (up to 35 Mbps, 1280 by 720 pixels, 30 frames per second) and PCM audio (ulaw, stereo) in .avi file format.

For simplicity, I always encode movies and TV episodes using the first format: “H.264/MPEG-4 AVC” video and “MPEG-4 AAC” audio.

Using Subler for Movies

I use Subler to add a preview image and chapters to a movie file. Subler will also add meta-info to indicate that the file is a movie type so that iTunes and iPad will recognize it accordingly. Here are the steps:

  1. Launch Subler. Subler won’t open a default project window so the only change you will see is that the top menu title changes to Subler.
  2. (Do this once) Go to menu Subler->Preferences and check the “Create Preview Images” for Chapters. This will cause Subler to generate chapter preview images when you save. Without this option, chapters will show up as black squares on the iPad. (QuickTime player and iTunes will generate the chapter previews on the fly if they don’t exist, but the iPad won’t.)
  3. Go to File->Open to find your mp4 or m4v iPad supported movie file. The project window will appear.
  4. In the project window, you will see a line for the “Video Track” for video and “Sound Track” (or sometimes “Stereo” track) for audio. Optionally, you may see a second audio track, a “Subtitle Track”, or a “Chapter Track”. Tracks with a check are enabled by default.
  5. If you don’t select any of the track line items (just click on any blank area in the project window), you should see the following appear at the bottom: Metadata, Artwork, and Other Settings.
  6. Go to menu “File->Import->Search metadata online” to find the movie description and artwork (preview image).
    • The Movie search tab will be selected by default.
    • Input the Movie Title, click the Search button, select the movie, and click the Add button.
    • Select a picture and click the “Set as artwork” button. Note that I could not find a way in Subler to change the artwork once it has been selected!
    • The Metadata and Artwork content at the bottom will be populated.
  7. Go to menu “Edit->Insert a Chapter Every X minutes” to add the chapters. I recommend selecting the “5 minutes” interval. (See below for how to add your own custom chapters at specific times.)
    • A “Chapter Track” will appear.
    • Make sure to check the chapter track to enable it.
  8. Commit your changes by going to menu File->Save. Subler will generate the chapter preview images and store them in a new “Video Track” with format “Photo – JPEG”. Leave this new video track unchecked.

Using Subler for TV Episodes

Adding meta-info to TV episodes is very similar to the above. The difference to keep in mind is that episodes have seasons and are numbered. iTunes and iPad will use the seasons and episode numbers meta-info to group TV episodes together (usually episodes together under a season). If you end the TV episode file names with the season and episode number like “S02E15” (Season 2, Episode 15), Subler will automatically pre-populate the search form. Here are the steps:

  1. Open the TV episode file using menu “File->Open”.
  2. Go to menu “”File->Import->Search metadata online”.
  3. If you have named your file with the season and episode number, Subler will select the TV Episode search tab and fill in the TV Show, Season #, and Episode # fields. If this didn’t happen, manually make the selection and inputs.
  4. Select the TV episode and artwork like above. (The first option for artwork is usually a screenshot from the episode. I recommend you select this so that each episode will have a unique preview image.)
  5. Verify the info in the Metadata tab content at the bottom. Make sure that the TV Season, TV Episode #, and Track # (aka episode number) is correct. The “Track #” will consist of the episode number and the total number of episodes in the season; for example, “5/21” meaning episode number 5 out of 21 episodes. Usually the Metadata will not have the total number of episodes; when you save without specifying it, the Track # will default to zero for total number of episodes. (I don’t think missing the total number of episodes will affect iTunes or iPad, but I have not tried it.)
  6. I don’t believe that the “TV Episode ID” is used by iTunes or iPad; however, it doesn’t hurt to make sure it is correctly filled-in. Basically, it is the season followed by the episode number; for example, “203” meaning season 2 and episode 3.
  7. I believe you can add chapters to TV episodes if you wish to. I don’t think it hurts and I’m not sure if iTunes or iPad will make use of chapters for TV episodes.

Use Subler to Increase Sound Volume

Subler has other functions which allow you to scale the video resolution or increase/decrease the sound volume. To double the sound volume:

  1. Select the “Sound Track” in Subler.
  2. In the Sound Settings that appear below, drag the Volume marker to the maximum “+6 db” setting. (From a quick google seach, “+6 db” effectively equals to double the sound volume.)

If you need to increase the sound volume further, you may wish to use a tool like AACGain.

Finally, import your movies and TV episodes to iTunes and/or iPad. They will show up under the correct Movies or TV Shows section, instead of the generic Videos section. Good luck!

Adding Custom Chapters to Subler

Adding custom chapters to Subler involves creating a raw text file, inputting the chapter times and names into it, and then dragging it into Subler. Subler will automatically recognize it as a Chapter Track.

The Subler documentation indicates that there are two formats for the chapter text files; I chose the more compact mp4v2 format. Here’s an example:

00:00:00:000 Opening
00:00:53:000 Robot Monkey Hullabaloo
00:13:56:000 Curious George, Spy Monkey
00:27:00:000 Curious George Rides a Bike
00:40:03:000 Curious George vs. the Turbo Python 3000
00:53:06:000 Monkey Fever
01:06:10:000 The Lucky Cap
01:19:14:000 Candy Counter
01:32:17:000 Gutter Monkey

Some comments about the above:

  • The file should contain a space between the time and the name, not a tab character.
  • The file extension should be “.txt”.
  • The first chapter must be at zero time. (If you don’t have a zero time chapter, then the rest of the chapters won’t be placed at the specified times.)
  • If you use TextEdit on Mac OS X, be sure to set plain text format by going to menu “Format–>Make Plain Text”. When saving, select the default “Unicode (UTF-8)” plain text encoding.

Before dragging the chapter file to Subler, make sure that Subler does not have any existing Chapter Track entry (you can delete the Chapter Track if it already exists). After dragging the chapter file to Subler, enabling it by checking the Chapter Track, and saving, you should see the following:

To verify the generated chapter images, open the movie file in QuickTime Player and select the “Show Chapters”. You should then see the following:

If there are any mistakes, just open the movie with Subler, delete the Chapter Track and “Photo – Jpeg” Video Track (which contains the generated chapter images), and start over with a corrected chapter text file.

For more info and advanced tips, see the following web forums and websites:

No Comments

Holy Cow, Batman! My Linux Server Got Hacked!

Linux 3 Comments

It was quiet, peaceful Tuesday night when I attempted to log into my Ubuntu Linux server as the root user. Permission denied, I got back. I tried it again. And again. Access denied. What the heck? I’m sure it was the correct password. I then tried all the passwords that it could be, from past to present. No luck. I got a sinking feeling. My root password was easy to remember and thus, easy to guess. I think my Linux server has been hacked!

No problem, I thought, I just have to reboot and log into single user mode… uh, unfortunately, my Linux server was sitting somewhere in cyberspace and I couldn’t do any of that. So I called up the service provider and they said, we didn’t touch your server and we don’t know who did. However, for $25, they can reset the root password. Having no choice, I accepted. Hours passed and finally I got an email with the new password.

I logged in, viewed the “/etc/passwd” file, and noticed two new users. Bad news, my server definitely got hacked. Good news, the hackers weren’t too sophisticated and had left a huge clue. I immediately copy the users’ info down and deleted them. Then it was off to google for what to do after a server hack. After looking at several websites, the most relevant one I found was How to restore a hacked Linux server.

What I got from the research was that once your Linux server is compromised, the best solution is to re-install the operating system. I did not want to do that because it would cost (a) money to ask the service provider to reinstall Ubuntu and (b) time for me to reinstall the applications. So I decided to play detective, find any damages, and fix them. Below are the steps I took.

1. Are there any unidentified users?

Run the following to list the users and groups:

more /etc/passwd
more /etc/group

Make a copy of the unknown users’ info, especially their usernames and ids, and delete them using the “userdel <unknown_username>” command. You should also check for and delete their home directories, located at “/home/username”.

2. Are there any strange processes running?

Run the following to list all the active processes started by the root or by the unidentified users:

ps -aef | grep root
ps -aef | grep <unknown_username>

Look for processes with weird names like “AkjwetSAG”; these are usually suspect. You can then run “lsof -p <process_id>” to get more info.

On my Ubuntu server, I found two processes, “avahi-daemon: chroot helper” and “/usr/sbin/console-kit-daemon –no-daemon”, that looked weird; but it turned out they were valid processes. After some quick online searches, I found that Avahi was used to detect network devices (not necessary for a server so it can be disabled or deleted) and console-kit was used for GUI related functions.

3. Are there any tracks left by the perpetrators?

Run the following to find any commands to change a password in the system:

cd /var/log
grep -R -i passwd *

This command returned several entries in the “auth.log” which included password changes for the unidentified user accounts. Strangely, there was no reference to a password change for the root user. By luck, there were two “Invalid user passwd from <ip_address>” messages containing the IP addresses of the perpetrators.

I then did a search on each of those two IP addresses:

grep -R -i <ip_address> *

I got back a ton of entries in “auth.log” which show numerous failed attempts using different usernames from these two IP addresses. I guess they kept trying until they got lucky. And they got lucky about five days ago.

Just for curiosity’s sake, I installed traceroute (it isn’t installed on Ubuntu by default) to see where the perpetrators came from:

apt-get install traceroute
traceroute <ip_address>

One of the IP address came from “CHINA-NETCO.edge3.SanJose1.Level3.net” and the other from “DC-PT-01-te1-2.ip4.012.net.il”. China and Israel. But there was no guarantee that those were the origins because the perpetrators could have hacked some machines there and then used those machines to hack into my server.

4. Are there any surprises left behind?

To be on the safer side, I installed and ran two rootkit scanners recommended by the website I found:

apt-get install rkhunter
rkhunter --check

apt-get install chkrootkit
chkrootkit

Both reported a clean bill of health. There were one or two false positives which I investigated and cleared. Finally, some good news! It looks like the hackers didn’t do anything damaging (cross my fingers).

5. Any strange new files?

One of the recommended actions was to look for new files that were created since the break-in. But I didn’t find this useful at all; it was like looking for a needle in a haystack. (Funny, in real life, robbers take stuff. In cyberspace, they leave stuff… malicious stuff.)

On Ubuntu, I couldn’t find a way to search for newly created files since 5 days ago. So I did the next best thing, which was to search for files last modified in the past 5 days.

find / -mtime -5

Unfortunately, the service provider had rebooted the machine as part of the password reset. So I got a ton of results back. Too much info to process.

6. What can I do to prepare for the next assault?

First, secure the root access. I changed the root password to an incomprehensible, random string of numbers, letters (lower and upper case), and special symbols. Try guessing that! And I will only share this root password with one other person as a backup.

Second, enable auditing of the server so we will have a record of every command issued by any user. This will make it easier to figure out what actions any user, legitimate or not, does on the server. I installed the Process Accounting (psacct or acct) service which this website recommended.

apt-get install acct
service acct start

By default, the service is configured to start on bootup. To double-check, I tried using the “update-rc.d acct defaults” command but got back a strange warning “update-rc.d: warning: acct stop runlevel arguments (0 1 6) do not match LSB Default-Stop values (1)”. I didn’t know what it meant so decided to use an alternative check:

apt-get install chkconfig
chkconfig acct

This command returned “acct on”, meaning that the Process Accounting service was configured to start on bootup.

Hopefully the above info will help you should you ever encounter the same misfortune. And maybe, the last section might help you to be better prepared.

3 Comments