How To Save A File In Vim / Vi Without Root Permission With Sudo On ...
Maybe your like
- Help Center
- Product Docs
- API Docs
- Technical Tutorials
- FAQ
- Community
- Help Center
- Tutorials
- How to save a file in Vim / Vi without Root Permission with sudo on Linux Cloud Servers
On a Linux system, vim and vi are the most popular text editors. We can edit the content of the files and able save it using vi/vim editor.
By default the server configuration files are owned by the root user, hence the normal user can not write the changes due to insufficient Permission.
This article will guide you to the basic commands about how to save a file after writing or modifying its content without Root Permission using sudo option.
Steps to edit the file /etc/hosts as a normal user.
# vi /etc/hosts
After making some changes (E.g Adding a new entry) in the file, save it by typing the following normal command which you can see that vim/vi CANNOT open the file due to the permission. :
:w!and then, Enter.


Now you try to save the file by followingpressing,
:w !sudo tee %:w – Write a file
!sudo – Call shell with sudo command
tee – The output of write command redirected using tee
% - Indicate the Current filename. Here it is /etc/hosts
And then, Enter.


Enter the password of the logged-in user and then Enter.

Press L to load changes in vim itself.
Now open the file again to see the changes.
# cat /etc/hosts
Related Tutorials
Creating Sudo User on Linux Cloud Servers
How to use sudo or sudoers to start, stop & restart Apache on Linux Cloud Servers
What do you think about this article?
Rate this article 5 4 3 2 1
Need assistance? Chat with us now! Try this guide to receive free bundled services at signup on a new free account.
Sign UpYour Feedback Is Important
We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.
New Powerful Arm Virtual Machines
- Ultra-high performance Ampere® Altra® Max cloud-native processors
- Provide as much as 30% better price performance than x86 VMs
- 2 CPU / 4GB RAM*, Ultra-fast SSD storage
Tag » How To Save In Vi
-
An Introduction To The Vi Editor | Enable Sysadmin - Red Hat
-
How To: Vi / Vim Save And Quit The Editor Command - NixCraft
-
How To Save A File In Vi / Vim Editor & Quit - PhoenixNAP
-
How To Save A File In Vim / Vi And Quit The Editor - Linuxize
-
How To Save & Quit In VIM Or VI - OSXDaily
-
Using Vi? Here's How To Open A File Then Save And Quit - MakeUseOf
-
How To Save And Quit A File In Vim - MakeUseOf
-
Saving Changes And Quitting Vi
-
Saving Files And Quitting Vi - UnixWare 7 Documentation
-
How To Save A File In Vi / Vim And Quit Editor - TecAdmin
-
How To Save File In Vi Editor? - YouTube
-
How To Save A File In Vi / Vim Editor In Linux - Tecmint
-
How To Exit (quit) Linux Vi Editor With Or Without Saving Changes Step ...
-
How To Exit Vim – Vim Save And Quit Command Tutorial