How can I programmatically unselect "View published content" checkbox for anonymous users? I am using Drupal 8. I want to programmatically unselect the View published content checkbox for anonymous users. 


  


How can I achieve this?
You have to insert this code in a hook_install() or hook_update() :

$role = \Drupal\user\Entity\Role::load('anonymous');
$role-&gt;revokePermission('your_permission');
$role-&gt;save();