How to Fix ‘dmesg: read kernel buffer failed: Operation not permitted’ in Linux

When diagnosing hardware initialization, USB device connections, or kernel module crashes in Linux, the dmesg command is an indispensable diagnostic utility. However, on modern distributions such as Ubuntu, Debian, Arch Linux, and Fedora, executing dmesg as a regular non-root user often returns the error: “dmesg: read kernel buffer failed: Operation not permitted”. This error is not a software defect; rather, it is a deliberate security restriction enforced by modern Linux kernels to prevent unprivileged users from gleaning sensitive memory addresses or hardware layout details.

Why Linux Restricts Access to the Kernel Ring Buffer

The kernel ring buffer contains diagnostic messages emitted by the Linux kernel from boot time onwards. Historically, any standard user could view this buffer freely. However, security researchers demonstrated that kernel messages frequently leak sensitive internal memory addresses, pointer values, and cryptographic state information that attackers can leverage to bypass kernel address space layout randomization (KASLR) protections.

To defend against local privilege escalation exploits, modern distributions enable the kernel.dmesg_restrict sysctl parameter by default. When this value is set to 1, only users with the CAP_SYSLOG capability or root administrative privileges can read the buffer.

Method 1: Execute dmesg with Administrative Privileges

If you only need to inspect kernel output temporarily, the standard and most secure method is invoking dmesg with elevated privileges via sudo.

  1. Open your Linux terminal emulator.
  2. Run the command with sudo:
    sudo dmesg
  3. To review recent hardware events conveniently with readable human timestamps, use:
    sudo dmesg -T | tail -n 50
  4. To monitor hardware events in real time (such as inserting a USB drive), use:
    sudo dmesg -wH

Method 2: Temporarily Relax dmesg_restrict via sysctl

If you are developing software or working on a test bench where running sudo repeatedly is inconvenient, you can temporarily allow non-root users to read the kernel buffer until the next system reboot.

  1. Check the current status of the restriction parameter:
    cat /proc/sys/kernel/dmesg_restrict
    (A return value of 1 indicates the restriction is active.)
  2. Disable the restriction dynamically by executing:
    sudo sysctl -w kernel.dmesg_restrict=0
  3. Verify that you can now run dmesg directly as an unprivileged user without encountering permission errors.

Method 3: Persistently Configure dmesg_restrict across Reboots

For dedicated personal workstations or development environments where persistent unprivileged access is desired, configure the setting inside the sysctl configuration directory.

  1. Create or edit a custom sysctl drop-in file using your preferred text editor:
    sudo nano /etc/sysctl.d/99-dmesg.conf
  2. Add the following configuration line:
    kernel.dmesg_restrict = 0
  3. Save the file and exit the editor (in nano, press Ctrl + O, then Enter, followed by Ctrl + X).
  4. Apply the configuration changes immediately without rebooting:
    sudo sysctl --system

Method 4: Alternative Inspection via journalctl and adm Group

On systemd-based Linux systems, kernel ring buffer messages are concurrently captured and indexed by the systemd-journald daemon. On many distributions, users belonging to the adm or systemd-journal group can read kernel messages without modifying sysctl security settings.

  1. Check your user group memberships by executing:
    groups
  2. If your user is not a member of the adm group, add your account:
    sudo usermod -aG adm $USER
  3. Log out and log back in to apply the updated group membership.
  4. You can now view the kernel log stream without sudo using the kernel flag in journalctl:
    journalctl -k -b

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.