Bash: permission denied for file write

I followed this tutorial guide on "How to Create Linux Proc Files in C Program using LKM".

I've successfully made my module and loaded it in. Now I want to echo to my proc file to make sure the method gets called that's supposed to be called.

I have tried:

$ echo "hello" > /proc/procEntry123       # But it says permission is denied!
$ sudo echo "hello" > /proc/procEntry123  # Same error message.

How can I elevate privileges to echo to this file? I am the sole user and admin on this system.


But it says permission is denied!

It probably says so because you set restrictive permissions when calling create_proc_entry(). (0644 translates to "u=rw,go=r", which only gives write permissions to the owner, which defaults to root.)

I put "sudo" in front of it - same message.

Redirections such as > or | are performed by the running shell, before it invokes sudo.

You have to either use sudo sh -c "echo blah > /proc/blah", or run a root shell with sudo -s.

I am the only user - this is my own personal machine!

This does not matter in Linux. File permissions will be enforced regardless of who uses the computer.

If you don't want that, either log in as root, or use pam_cap to give yourself the cap_dac_override capability – but either method will cause troubles sooner or later.