Separability properties of free groups and surface groups