I prefer going to Rabat by train, but yes the CTM bus is fine too. The CTM station is a bit outside of town. You can buy CTM tickets at the main central bus station but then you have to wait for the CTM bus to take you to their own station outside of town, then on to Rabat. Or you can just ask a taxi to take you directly to the CTM station.
Rabat is really nice. I like it more than Casablanca and it's a cleaner and more modern city compared to Tangier.