• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to password protect a file Using VIM

{{postValue.id}}

To Password Protect A File Using VIM

Password protecting a file is very easy in Linux and this tutorial covers the method to password protect a file using Vim. It is so simple, we will show you how to secure a file at the time of its creation as well as after opening it for modification.

Password Protecting A File

Before you begin, you need to install the full version of Vim, and for that simply run the following command.

[root@linuxhelp ~]# yum install vim
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
.
Installed:
  vim-enhanced.x86_64 2:7.4.160-2.el7                                                                              

Complete!

Vim has a -x option which enables you to use encryption when creating files. Once you run the vim command below, you’ ll be prompted for a crypt key:

[root@linuxhelp ~]# vim -x file.txt
~
~
~
Enter encryption key: *******
Enter same key again: *******

If the crypto key matches after entering it for the second time, you can proceed to modify the file.

crypto

In case you enter a wrong password (or no key), you’ ll see some junk characters.

junk

That’ s all! With this simple trick you can password protect a file via the Vim text editor in Linux.

Tags:
elijah
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What command is used to generated encrypted set of file?

A

Install and use mkpasswd

Q

Is this work with other editors ?

A

No it will work only with vim

Q

How to remove a encrypted password from the file.

A

You can update the original password with an empty password. Start vi/m with -x option, you’ll be prompted for new password, leave it empty/blank and press Enter twice.

Q

But if I write a python program with encryption enabled then the file doesn’t compile. What to do?

A

Try to compile without encryption. May be it will work.

Q

How can I reset the password using the current password? What If I forget the password later. Is there any way to reset the password without entering the old password? I mean is there something like security questions etc?

A

Do not forget the password, otherwise you’ll not be able to view the contents of the file again. And to update the password, open the file for editing and type [Esc] and :X then save changes to the file like this :w before closing it.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Owen ?
How to add SSH key to my Gitlab account

I need to add the SSH key in my gitlab account. How to do so ????

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.