It's not illegal to have a duck as a pet if you bought the duck from a duck breeder.
However if the duck is a wild duck then you need a permit to legally keep the wild duck as a pet.
if you do not have a permit to keep the wild duck as a pet then you could be fined.
But for most other ducks that are not wild ducks you can keep them as a pet without a permit depending on your location.
To keep a duck as a pet you really need to have a rural property with at least a few acres so that the duck can roam around.
Also if you live in a town or city they may prohibit ducks as pets so check with your local city or town ordinances because the town or city could make you get rid of the duck or ducks.
I would not want a duck unless I had a rural property for it.