Is ghostwriting a good thing to do? How does one get into ghostwriting? Do agents ever represent ghostwriters?
Ghostwriting is a great thing to do, because it gives a writer experience in creating a long-form work and in meeting deadlines; often the writer has to shape a story out of material they wouldn't normally choose (thus forcing them to be even more creative); it introduces the writer to a publisher; the writer becomes familiar with the publishing process and people within the industry and is thus more likely to (a) get more ghostwriting work and (b) have their original work looked at by the publishers they have worked for as a ghostwriter.
The most direct route to ghostwriting is being a journalist. A ghostwriter is usually required for a non-fiction project that has a prominent subject (usually a person), so for a journalist it's a relatively familiar process (lots of interviewing and then shaping a story for a particular readership). If you're not a journalist, you'll need to have some relevant credits to present to a publisher, to prove that you can write something of book length and also that you are used to working with a subject who may have nothing in common with you. In other words: if you're not a journalist, it's hard.
Yes, agents can represent ghostwriters but they are usually writers who already have (non-fiction) books of their own, and we put them forward for ghostwriting gigs if a publisher says they're looking for someone.
Ghostwriting is not the easiest form of writing, because you have at least two masters (the subject of the book and the publisher) and the deadlines are often steep. But if you're not too attached to seeing your name on the cover of a book and you like a challenge, it's an effective way to make a living as a writer.