how to set a node to anonymous author?
$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();