Electronic Frontier Foundation has a detailed article advising you of your (lack of) rights when you enter and leave the United States (this applies to citizens and non-citizens). Here is some basic advice, but check out the article for lots of good advice regarding encryption, use of clouds, backups and other advice, much of it useful even when you are not traveling:
Border agents have a great deal of discretion to perform searches and make determinations of admissibility at the border. Keep in mind that any traveler, regardless of citizenship status or behavior, can be temporarily detained by border agents for more detailed questioning, a physical search of possessions, or a more extensive physical search. Refusal to cooperate with searches, answer questions, or turn over passwords to let agents access or decrypt data may cause lengthy questioning, seizure of devices for further examination, or, in extreme circumstance, prevent admission to the country. For this reason, it may be best to protect your data in ways that don’t require you to have awkward confrontations with border agents at all.