how to set a node to anonymous author? Change node author works :
$node = \Drupal\node\Entity\Node::load($nid);
$node-&gt;set('uid','45');
$node-&gt;save();

But i don't know how to set it to anonymous user ? or unset it ?
 $node = \Drupal\node\Entity\Node::load($nid);
 // set uid to anonymous ?
 $node-&gt;save();
$node-&gt;set('uid', 0); $node-&gt;save should have worked. Maybe you forgot to flush caches.
To programmatically set the author to anonymous user on any entity you can call $entitiy-&gt;setOwnerId(0); and then $entity-&gt;save();, done.
$entity-&gt;setOwnerId(0);
$entity-&gt;save();