Legal? Check with a lawyer. But, yes, it's legal. No law against it. Have a lawyer confirm that.
Still, it's probably not precisely what you want to do.
The comments below about assumability (FHA being assumable, others generally not, and you could trigger the due on sale clause) are correct.
There are other structures/techniques that would work better. They'd still risk trigger the due on sale clause, but they'd protect you far better. Among them: a land contract or a wrap mortgage. (You can research the basics online.) Offering your home on a lease-option or lease-purchase basis is another possibility. Or using a land trust--where you'd put your property into the trust and add the potential buyer as the resident beneficiary. That structure really would work best, but it's a bit complicated. See http://www.landtrust.net
for more information.
Again, I'm not a lawyer, so this isn't legal advice. But, to best protect yourself, you should retain as much control over the property as possible. That means, for instance, renting the property now and selling later. That way, if the buyer defaults (and the paperwork is done properly), you only have to evict the non-paying tenant, not foreclose on the owner of the property.
Check with a good lawyer--one who understands real estate and creative financing--for his/her suggestions on how to proceed.
Hope that helps.