I made lengthy changes to a configuration file on a Ubuntu Linux computer with the vi editor. Unfortunately, I forgot to sudo first, so now I'm in the editor, but can't save my changes because of missing rights. Can I retroactively sudo the user on that terminal, or what would be the best course of action to take?

link|improve this question

67% accept rate
2  
See also stackoverflow.com/questions/1005/… – therefromhere Oct 10 '09 at 20:00
feedback

3 Answers

up vote 10 down vote accepted

In this case, I wrote file with :w /tmp/tmpfile. Then I go out and move /tmp/tmpfile to my old file with sudo rights.

That's it !

link|improve this answer
this is what i end up doing, but i like wfaulk's answer .. if i can only remember it the next time i do this! :) – quack quixote Apr 19 '10 at 14:59
feedback

From SO:

:w !sudo tee %
link|improve this answer
feedback

Couldn't you open another terminal and temporarily change the file's access rights?

link|improve this answer
1  
This is a bad idea. Probably wont ever be a big security problem, but it could be, and there's better and simpler solutions (like writing to a temporary file, or better, the :w !sudo tee % solution wfaulk posted – dbr Oct 10 '09 at 20:07
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.