0

More times than I want to admit I will open a config as a non-super user and will go about making the changes I need. As soon as I save in nano, or vi I am met with permissions errors.

At this point I c/p foo my way around so I can close and reopen with sudo.

Is there a way to escalate to a super user in order to save without closing and reopening in vi or nano?

1 Answers1

1

I don't know about nano, but I do know that you can write a file you don't have permission to access in vim. Try running this command:

:w !sudo tee %

This will save the file even if you don't have permission to it. Nathan Long has a great explanation of how this works here, but I'll give a short explanation too.

:w doesn't mean save, it means write. So in this case, :w !foo means write into the external command foo. In this case, the external command is sudo tee %, where % is the name of the current file. Tee will write to a given file and STDOUT simultaneously, and since we run it with sudo, it has the necessary permissions to write the file.

DJMcMayhem
  • 126
  • 4