It's very likely that sed -i
will create a brand new file then replace the original with it. That means you would have to have write access to the directory /etc
, not just the file.
None of the tools that create a new file will work without that power, and that is rightly so: /etc
is a very important directory and you probably shouldn't be playing there without permission :-)
One solution is to put your file somewhere where you can modify it, then just create a soft link to it from /etc
. something like:
ln -s /my_directory/my_file /etc/my_file
You'll need root powers to create the link of course. The soft link will prevent the linkage from disappearing should you do a new-file/rename operation, since the soft link is simply a file containing the target path (which, unlike the inode, won't change with sed -i
).
And this limits their power to changing that file and that file only. No possibility for security holes by opening up the permissions on /etc
.