insmod says Operation not permitted when loading a kernel module
insmod: ERROR: could not insert module HelloWorld.ko: Operation not permittedShort answer
Operation not permitted is the kernel's EPERM reply to a module load. The kernel documents two reasons: the caller lacks the CAP_SYS_MODULE privilege (run it as root), or module loading has been turned off with the kernel.modules_disabled switch, which only a reboot clears.
Fix it fast
1Find out which cause you have
Ask the kernel log what it said about the failed load; insmod itself only prints a general message.
sudo dmesg | tail -n 202Match what you see, then jump to its fix
What does the error look like?
insmod: ERROR: could not insert module HelloWorld.ko: Operation not permitted
Cause 1 of 2
insmod ran without root privilege
1Check
Loading a module needs the CAP_SYS_MODULE capability. A normal account does not have it.
id -u2Fix
Run the command as root. For a module in your build folder, give insmod the path to the .ko file.
sudo insmod ./HelloWorld.ko3Verify
The module shows up in the loaded list.
lsmod | grep -i helloworldConfirmed by man7.org
Cause 2 of 2
Module loading is disabled on the running kernel
1Check
The kernel.modules_disabled toggle stops all loading and unloading once it is set to 1, and it cannot be set back to 0 without a reboot.
cat /proc/sys/kernel/modules_disabled2Fix
If the value is 1, reboot the machine. To find what sets it at boot, search your sysctl configuration for the setting.
grep -rn 'modules_disabled' /etc/sysctl.conf /etc/sysctl.d/ /usr/lib/sysctl.d/ 2>/dev/null3Verify
After the reboot the value reads 0 and the load works.
cat /proc/sys/kernel/modules_disabled
sudo insmod ./HelloWorld.koConfirmed by kernel.org
How do I stop it coming back?
- Use sudo for module operations, and prefer modprobe for modules that are installed, since the insmod manual recommends it for most users.
- Only set kernel.modules_disabled after every needed module is loaded, and document it.
- Read dmesg first: insmod reports only the most general messages.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
insmod refuses to load a kernel module: Invalid module format
insmod: error inserting './hello.ko': -1 Invalid module format
The kernel rejects a module that was not built for the exact kernel that is running.
3 causes, each with a fixServers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix