When a lot of guitarists start out, they want to play along with CD's, and show their friends all the songs they've learned. I myself sit in my room and figure out how to play songs by ear for fun.
For beginner guitarists, punk rock is a very easy way to learn to play by ear, since it consists mainly of power chords and basic rhythms. But before choosing a song to learn, make sure you know what the tuning for the song is (standard, drop D, drop D tuned down one whole step, etc.).
To start out, pick a song that is pretty basic, like a Nirvana song or a Blink-182 song. Listen to a riff, and then try to figure out what the first note is. If you play the CD and play the note or chord at the same time, you should be able to tell if it is the same note or not, if you listen closely enough. If it does not sound right, move the note or chord up and down one fret. If the note sounds way off, you may even try it on different strings. Do this for the rest of the riff, and eventually you'll have figured out how to play the entire riff.
As you develope your ear and guitar skills, you will be able to figure out how to play more advanced riffs. You will be able to figure out chords and scales. You'll be able to distinguish the sound of a single note, and the sound of that same note with an octave played together.
Here is a list of some bands to play along with:
2. The Offspring
4. Linkin Park
5. Some System of a Down
6. Red Hot Chili Peppers
8. Some Foo Fighters
Intermediate:1. Some Black Sabbath
2. Some System of a Down
3. Some Red Hot Chili Peppers
5. Rage Against the Machine
6. Some Foo Fighters
Advanced:1. Black Sabbath
2. The Beatles
3. Led Zeppelin
7. Ozzy Osbourne
So anyway, I hope this article is helpful to anyone learning to play by ear. Please give me feedback (no pun intended).