First off, it's best to find hand rails that are square, instead of round. Round rails are HARD to keep your balance on. You can slide them all you want, but make sure you are either awesome or like pain first.
It's also good to start with a shorter handrail - one that goes only 3 to 5 steps. Not more. Work up to bigger rails. Start small, take your time, and you'll spend more time skateboarding and less time recovering from injuries!
So you have the perfect rail, and you're ready to go - great! Here's how it works: You need to ollie up onto the rail (so you need a STRONG ollie), and do a regular board slide, except that you need to lean with the rail. That's the hard part, and it will take some time to get used to. Don't lean too much or too little - lean just enough. The only way to learn how much that is is to practice. And, in case you've managed to never see a funny home videos TV show, handrails are the best possible place to hit your crotch on. It's hilarious on TV, but strangely not so much when it happens to you. Wear a cup!
In fact, you might want to wear lots of other pads, too. You should already be wearing a helmet, but shin guards and elbow pads and knee pads and the works wouldn't hurt either!
finally, when you come off of the rail you will be going fast, so make sure to bend your knees deep when you land and land with your feet over your trucks. Also, make sure there is enough space at the end of the rail for you to ride out on.