Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
"but I'm sudo", no actually you're su the super user. It stands for something like "Take this action as the super user" since the second half is do as in "do this, do that" – TheZ Sep 28 '12 at 23:58
up vote 8 down vote accepted

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.

share|improve this answer
No, don't suggest that the inexperienced log in as root. That's a recipe for disaster! – Darth Android Sep 28 '12 at 22:24
@DarthAndroid: If they can write a kernel module, they should have enough common sense not to do that. – grawity Sep 28 '12 at 22:25
But the problem isn't that you're suggesting this to an experienced user, it's that everyone, their brother, and their dog who visits this post will see that you suggested just throwing caution to the wind and logging in as root. There are already 23 views on this question, so essentially 23 people now might think this is okay. :) Just a thought... With that said, a lot of people will log in as root no matter what we tell them, so I guess it doesn't really matter... – jmort253 Sep 29 '12 at 9:03
Hi guys - I chmod 777'd the proc file and it was solved. This excercise was purely experimentation so it doesn't matter that the file is rw for all. Thanks for your help! – Sam Sep 29 '12 at 17:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .