Why can't I edit files owned by root but being e.g. somewhere deep in my personal directory, it says:
sudoedit: existingFile: editing files in a writable directory is not permitted
While I have the following function defined:
function sunano {
export SUDO_EDITOR='/usr/local/bin/nano'
sudoedit "$@"
}
And I edit like this:
sunano existingFile
Where the file is indeed owned by root:
ls -l existingFile
Proves that:
-rwxr-xr-x 1 root root 40 Jun 15 2015 existingFile
Best Answer
The manpage says
If you can write to the directory containing the file, then you can edit it in practice without needing
sudoedit
(although you may not be able to read its current contents): you can move it out of the way and create a new file with the same name. In your particular case, you can read the file, and you should find that at least some editors will allow you to edit it (at least those which save files by writing a temporary file and renaming it into place).The reasoning behind this feature is given in
sudo
bug 707: basically, allowing users to edit files in directories they can write to withsudoedit
can allow them to circumvent the restrictions set up insudoedit
’s configuration (and effectively edit any file on the system).