Yes, a cash for keys agreement is legal, as long as it is done properly and in compliance with applicable laws and regulations. The agreement must be voluntary, with no coercion or threats, and the amount offered must be reasonable and fair. Bear in mind that a cash for keys agreement is not a substitute for the legal process of eviction. If a tenant refuses to vacate the property voluntarily or does not comply with the terms of the agreement, the landlord may still need to pursue legal eviction proceedings.