password protection for a file in linux through vim

Satish Tiwary's picture

Security Key can be assigned to to a file in a Linux Machine before creation of that file.

Suppose you want to secure a file before making it or you can say "secure a file at the time of it's creation".

May be you guys already know how to secure a file which is already there but this article is all about  how to protect a file at the time of it's creation or you can say protect a file with a secret key before it's creation.

We use many type of security likes

  • encryption
  • gpg password protection
  • zip password protection

But all these needs there must be a file already created and then you have to apply these tricks on them.

But here what i am going to explain you that you don't need to do anything after creation of file.

As you create file it will be automatically get password protected.

Its a easy and simple trick but very useful. Just for testing purpose we are taking a file linux.txt here.

 

Explanation of File Security using VIM  Editor.

#vim -x filename

 

[root@localhost test]# vim -x linux.txt

you can clearly see the above commmand in which -x option is used to provide password to file linux.txt


 

now the file(linux.txt) will be protected with a passphrase.

 

How to change that passphrase?

 

#vim +X filnename

#vim +X linux.txt


"linux.txt" 3L, 79C
Enter encryption key:

 

Example question: I want to make a file satish.txt but i dont have time to apply security after every file i create. So i have decided to apply the above rule so that our file satish.txt get automatically password protected.

Answer:

We will run

#vim -x satish.txt

hello satish tiwary your file is secure now!

:wq!

now save and exit the file with :wq!

 

Let's have a look on other possiblity of securing a file.

There is more other way to secure a file but here i have mentioned the way you secure a file before you make that file.So your content in the files are secure with the time it's written.This is the dynamic way to secure your content if you are writing something important and you don't want to take any risk.

Other methods of securing a file is encrypting a file after the file created using gpg encryption method.

You can also provide security to your compressed files.
To know how to provide security to compressed files in Linux you can read our articles on securing zip files.

You can also secure your file using openssl.we will write a dedicated article on openssl very soon.

You can also secure a file by breaking a file in to multiple pieces using split command.

No users can read the contents of files before joining every parts of it together.

Rate this article: 
Average: 3.6 (8 votes)

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.