We use two independent Apple IDs in Messages.app, which I want to keep private. But if I log out of one and log in with the second one within Messages (not the computer itself, but the Apple ID in the Messages.app), the conversations from the previous account are still online, and the second person can see them. Is there a way to link the conversations to the account, so that they dont show up unless you are logged into the account that sent them?
I haven't found a way to share iCloud accounts for a different reason. Apple suggests keeping separate computer accounts to handle multiple users on a single computer and provides no support for your use case.
Each computer account can have it's own iCloud account associated without conflict. Using fast user switching to move between logins is the safest way. Using two different iCloud accounts with Messages (or any other service) at the same time on the same login is not supported. You can end up with undesirable behavior if you bounce between iCloud accounts as a single user.
iTunes store accounts seem more robust with respect to switching under a single login because Apple has been forced to deal with large number of users who use different accounts for the iTunes Music Store and iCloud and have purchases spanning both accounts and need to log in/log out to validate DRM.