ive done it a few times, so ill throw out some tips for you.
most train workers dont give a damn, some are jackasses and tell you to get off. the only one you really have to worry about is a yard boss, who will take pleasure in having you arrested. they only hang out in train yards, usually in an office somewhere.
as for actually riding trains, theres a lot of stuff to look for / look out for. first of all, dont get on a moving train, no matter how slow its going. its a really easy way to get yourself killed, especially if youre wearing a heavy pack.
box cars are usually the nicest ride you can find because they are completely sheltered. however, if the door of a boxcar shuts, there is no way to open it from the inside! ive heard stories of people getting trapped inside boxcars for weeks before anybody found them, so make sure to use a rock, stick, or shoe to keep the door from closing.
a lot of grain cars also have a little hollow spot in the back which makes a nice place to hang out and ride, and if its warm out a flat car is nice to feel the wind go by. ive heard of people getting rides up front in the engine if the engineer spots them, but ive never been willing to take the risk of getting seen.
which leads to my next tip: get on the train from the outside of a bend, that way the engineer cannot see you get on in his mirror.
bring lots of warm clothes to shelter you from wind / rain, and also to make something of a pillow, since there are very few soft things in trains. also get ready to miss a train, not see anyone else for the rest of the day, and have to sleep in a cow field. its never as bad as it sounds.
i could probably go on for a long time, but i dont feel like it, so PM me if you have any questions. besides skiing, i probably feel happiest when im hoping trains. theres something very relaxing about being entirely at the mercy of something you cant control.