Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
2  
See also stackoverflow.com/questions/1005/… – therefromhere Oct 10 '09 at 20:00

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 !

share|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

From SO:

:w !sudo tee %
share|improve this answer

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

share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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