Linux prevent unprivileged users from viewing dmesg

You can prevent unprivileged users from viewing the dmesg logs on Linux by using the following steps:

  1. Edit the sysctl configuration file:
sudo nano /etc/sysctl.conf
  1. Add the following line to the end of the file:
kernel.dmesg_restrict = 1
  1. Save and close the file.
  2. Reload the sysctl configuration:
sudo sysctl -p

After these steps, unprivileged users will no longer be able to view the dmesg logs, as the dmesg_restrict flag will restrict access to it.

Note: Only the root user or users with the CAP_SYSLOG capability will be able to view the dmesg logs.

Leave a Comment