How to password protect text files using vim on linux (or macos)

Apart from creating and editing text files, we can also encrypt files using Vim editor. This brief guide shows you how to password protect text files using Vim editor in Linux and Unix-like operating systems.


Vim editor is a powerful and feature-rich application used to to create and edit text files. It is a cross-platform application, so you can use it on all platforms, including Android, iOS, Linux, Unix, macOS, and MS Windows.

Vim is not just for creating or editing files, we can even encrypt text files using Vim editor. To put this in other words, Vim is able to write files encrypted, and read them back.

The encrypted text cannot be read without the correct key. Whenever you try to edit an encrypted file with Vim, you will be asked to enter the right key.

If you type the same key as that was used for writing, you can read the text again. If you use a wrong key, you will see some junk and messy characters.

Enough talk! Let us go ahead and encrypt files using Vim editor in Linux.

Install Vim Editor in Linux

Vim is available in the official repositories of almost all Linux and Unix distributions. You can install Vim using your distribution’s default package manager.

To install Vim editor in Alpine Linux, run:

Install Vim editor in Arch Linux:

Install Vim editor in Debian, Ubuntu, Pop!_OS, Linux Mint:

Install Vim editor in Fedora, RHEL, AlmaLinux, Rocky Linux:

Install Vim editor in openSUSE:

Install Vim editor in Gentoo:

Install Vim editor in FreeBSD desktop:

Install Vim editor in FreeBSD server:

Password protect text files using Vim editor in Linux

All the steps given below are tested on a Fedora 34 system. However the steps are same for other distributions.

The typical way to encrypt a text file using Vim is to use the 😡 option (lowercase x ) when creating a new file.

Step 1: Open your text file using Vim editor with -x option:

Step 2: Type your passphrase twice and hit ENTER key.

Important note: Do not lose the password. You can’t read the file without the right passphrase. Also if you make a typing mistake when entering the key, you might not be able to access your text back!

Step 3: Now press the i key to enter into insert mode. Start typing or editing the file as the way you do normally.

Step 4: Once done with the editing, press ESC to exit from the insert mode and type :wq to save the file and close it.

Congratulations! We just encrypted a text file with a password using Vim.

Access or read password protected file using Vim editor

Whenever you try to access or edit the password-protected file using Vim, you will be prompted to enter the correct passphrase.

Upon entering the right passphrase, the text file will be readable again.

If you don’t enter the correct password, the text will simply look like a mess.

Please note that you can access the password-protected file only using the Vim editor, but not from other text viewers.

If you try to view the the password-protected file using other CLI or GUI text viewers and editors, you will see nothing but some junk characters as shown in the below picture.

Change encryption method in Vim editor

Starting from version 7.4.399 and above, Vim uses blowfish2 encryption method by default to encrypt files.

To view the current encryption method, simply open the encrypted file and type the following in the command mode:

You will see the current authentication method of Vim editor:

The bluefish2 is the strong and recommended encryption method in the latest editions of Vim editor.

If you’re using any old versions, you should change the encryption method using command:

Here, cm refers cryptmethod .

If you wish to switch to the less secure encryption methods, such as blowfish and zip , run:

After choosing the encryption method, don’t type :w to apply the changes.

I strongly recommend you to always use blowfish2 method , which is best for security.

Refer cryptmethod help section for more details.

To open the cryptmethod(cm) help section, run the following in command mode:

Sample output:

Change password of a file using Vim editor

If you want to change the password of an encrypted file, you should know the current password.

Step 1: Open the encrypted file using Vim:

Enter the current passphrase to view its contents.

Step 2: Type :X (Upper case x) and hit ENTER key. Next, type your new password twice and press ENTER key.

Step 3: Type :w to apply the changes to the file.

Remove password from a file using Vim editor

Step 1: Open the file in Vim editor:

Step 2: Type :X (Upper case x) and hit ENTER key. Next, DO NOT ENTER any password. Just leave the password field blank and press ENTER key twice.

Step 3: Finally, type :w and hit ENTER to save the changes to the file.

Now you can open the file without a password.


In this guide, we learned how to encrypt a text file or password protect a text file using Vim. In addition, we also discussed how to view and change the authentication method in Vim editor.

Finally, we saw how to change the password of text files and how to remove the password completely using Vim editor.

Learning Vim is worth your time. Learn one topic per day. You will be a master in Vim in couple days.

Useful Vim tips and tricks on this blog:

Chris Hoffman is Editor-in-Chief of How-To Geek. He’s written about technology for over a decade and was a PCWorld columnist for two years. Chris has written for The New York Times and Reader’s Digest, been interviewed as a technology expert on TV stations like Miami’s NBC 6, and had his work covered by news outlets like the BBC. Since 2011, Chris has written over 2,000 articles that have been read nearly one billion times—and that’s just here at How-To Geek. Read more.

The vim text editor, a standard tool included on Linux and macOS, can quickly encrypt text files with a password. It’s faster and more convenient than encrypting a text file with a separate utility. Here’s how to set it up.

Make Sure Your System’s Vim Has Encryption Support

Some Linux distributions, including Ubuntu, include a minimal version of vim by default, intended only for basic text editing. For example, Ubuntu calls this package “vim-tiny”. If you try to use encryption in such a minimal version of vim, you’ll see a “Sorry, this command isn’t available in this version” message.

You may need to install the full version of vim to get this feature on your Linux distribution. For example, on Ubuntu, you can get the full version of vim that by running the following command:

The version of vim included by default with macOS does include encryption support, so you don’t need to install anything else on a Mac. Just launch a terminal window from Finder > Applications > Utilities > Terminal and the commands will work the same on macOS as they do on Linux.

How to Encrypt a File With a Password

The basic process is relatively simple if you know how to use vi. If you don’t, you might get hung up on vi’s modal interface. When you open a text file in vim, there are two modes. By default, you’re in a “command mode” where you can use the keys on your keyboard to perform commands. You can also press “i” to enter “Insert mode”, where you can type normally and move the cursor around with the arrow keys, as you would in other text editors. To leave insert mode, press “Esc” and you’ll be back to command mode.

First, launch vim. For example, the following command will launch vim and point it at a file named “example” in the current directory. If that file doesn’t exist, vim will create a file named “example” in the current directory when you save it:

You can also point vi at another path with a command like the below one. You don’t have to create a file in the current directory.

Edit the file normally. For example, you can press “i” to enter insert mode and then type text normally. While editing a file, press Esc to ensure you’re in command mode and not insert mode. Type :X and press Enter.

You’ll be prompted to enter a password, which the text file will be encrypted with. Type the password you want to use, press Enter, and type it again to confirm. You’ll need to enter this password any time you want to open the file in the future.

Vim will warn that you’re using a weak encryption method by default. We’ll show you how to use a more secure encryption method later.

A password will be associated with the current text file in Vim, but you’ll need to save your changes before the password is actually assigned to the file. To do this, press Esc to ensure you’re in command mode, and then type :wq and press Enter to write the file to disk and quit Vim.

The next time you attempt to open the file in Vim—for example, by running “ vi example “—Vim will ask you for the password associated with the file.

If you enter the wrong password, the contents of the file will be gibberish.

Warning: Don’t save the file if you open it and see gibberish. This will save the corrupted data back to the file and overwrite your encrypted data. Just run :q to quit Vim without saving the file to disk.

There’s one other shortcut you can use here. Rather than creating or opening a file with “ vim /path/to/file “, you can run the following command to have vim create or open a file and make it immediately prompt you to encrypt the file with a password:

Note that you need to use a lower-case x here, while you need to use an upper-case X when running the associated encryption command from inside Vim.

How to Enable Stronger Encryption in Vim

By default, Vim uses very bad encryption for these files. The default “zip” or “pkzip’ encryption method is backwards compatible with versions 7.2 and below of vim. Unfortunately, it can be cracked very, very easily—even on hardware from the 90’s. As the official documentation puts it: “The algorithm used for ‘cryptmethod’ “zip” is breakable. A 4 character key in about one hour, a 6 character key in one day (on a Pentium 133 PC).”

You should not use pkzip encryption for your text documents if you want any security at all. However, Vim provides better encryption methods. Version 7.3 of Vim released in 2010 added a “blowfish” encryption method, which is better. Version 7.4.399 released in 2014 included a new Blowfish encryption method that fixes security problems in the original “blowfish” encryption method, and dubs it “blowfish2”.

The only problem is that files you create with stronger encryption methods require these newer versions of Vim. So, if you want to use “blowfish2” encryption, you’ll only be able to open that file with Vim versions 7.4.399 and above. As long as you’re fine with that, you should use the strongest encryption method possible.

To check which encryption method a file is using, open the file in vim, press the Esc key to ensure you’re in command mode, type the following command, and press Enter.

The “cm” here stands for “cryptmethod”.

You’ll see the encryption method used for the current file displayed at the bottom of the vim screen.

To choose an encryption method, run one of the following commands. The “blowfish2” encryption is best for security.

Once you’ve selected your encryption algorithm, use the :w command to write the file to disk or the :wq command to write the file to disk and quit.

The next time you re-open the file in Vim, it won’t complain about a weak encryption algorithm. You’ll also see the encryption algorithm you selected at the bottom of the vim screen when you open the file.

How to Change or Remove a Password

To remove a password from a file, open that file in Vim and run the :X command. You’ll be prompted to provide a new encryption key. Enter the new password you want to use here. To remove the password completely, leave the password field blank and just press Enter twice.

Save the file and quit afterwards with :wq . The file will be decrypted, so you won’t be prompted to enter a password when you open the file in the future.

Be sure to remember whatever password you set or you won’t be able to access the contents of the file in the future.

Vim is a popular, feature-rich and highly-extensible text editor for Linux, and one of its special features is support for encrypting text files using various crypto methods with a password.

In this article, we will explain to you one of the simple Vim usage tricks; password protecting a file using Vim in Linux. We will show you how to secure a file at the time of its creation as well as after opening it for modification.

To install the full version of Vim, simply run this command:

How to Password Protect a Vim File in Linux

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:

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

Vim File Password Protected

Once your done, press [Esc] and :wq to save and close the file. The next time you want to open it for editing, you’ll have to enter the crypto key like this:

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

Vim Content Encrypted

Setting a Strong Encryption Method in Vim

Note: There is a warning indicating that a weak encryption method has been used to protect the file. Next, we’ll see how to set a strong encryption method in Vim.

Weak Encryption on Vim File

To check the set of cryptmethod(cm), type (scroll down to view all available methods):

Sample Output

You can set a new cryptomethod on a Vim file as shown below (we’ll use blowfish2 in this example):

Then press [Enter] and :wq to save the file.

Set Strong Encryption on Vim File

Now you should not see the warning message when you open the file again as shown below.

You can also set a password after opening a Vim text file, use the command :X and set a crypto pass like shown above.

Check out some of our useful articles on Vim editor.

That’s all! In this article, we explained how to password protect a file via the Vim text editor in Linux.

Always remember to appropriately secure text files that could contain secret info such as usernames and passwords, financial account info and so on, using strong encryption and a password. Use the feedback section below to share any thoughts with us.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Vim is a powerful, feature-rich, highly extensible text editor that is used in all Linux OS. It is available in repositories of nearly all major Linux distributions. Because of its performance and low memory consumption, it is the top choice of most Linux users. One another useful feature of the Vim editor is its built-in support for encryption. It is very helpful particularly in a multi-user environment where you can encrypt your files so that no one can access your confidential information.

In this article, we will be going to discuss how you can password protect your files in Vim editor. We have used Debian 10 OS for explaining the procedure mentioned in this article.

Installing Vim

As Vim is available in the official Debian repositories, so we can install it using apt-get command. Launch the terminal and enter the following command in order to install vim editor in your Debian OS.

The system will ask for confirmation by providing you with a Y/n option. Press y to confirm and wait for a while until the installation is completed on your system.

Creating a password-protected file using Vim

Once you are done with installing vim editor, open it.

Now create a file through Vim editor by using –x flag followed by file name as follows:

For instance, I am creating a file name as testfile.txt:

The -x flag will enable you to create encrypted files.

You will be asked to enter the encryption key. Type the key and press Enter and you will be asked to renter the same key.

Now you can add the text in the above created file by pressing –i key. Once done, press Esc key and type :wq to save and exit the file.

Now the password-protected file is successfully created using the Vim editor.

Accessing password-protected file

The encrypted file created by Vim editor can be read and accessed only through Vim editor. If you try to access it by other means, it will be shown to you as junk text.

For instance, if we try accessing it using cat command:

This is how our password-protected file will look like:

So now open it using the Vim editor using the following syntax:

Now you will be asked to enter the same encryption key used for encrypting the file. Enter the key and now you will be able to see the original content.

Changing password for a file in vim

The password for the encrypted file can also be changed. For that open the file in Vim and hit :X.

You will be asked to enter a new encryption key and confirm it. Type the key twice and press Enter.

After that, press Esc and type :wq to save and exit the file.

Removing password

To remove the password from the encrypted file, open the file in Vim editor and hit :X.

Now when you will be asked to provide encryption key, leave it blank, and just press Enter twice. Then press Esc key and type :wq to save and exit the file.

So now, you will not be asked to provide encryption key when accessing the file.

We have discussed how to password protect files using vim editor. It is a great way of protecting files within an editor. However, while encrypting make sure to remember the passwords used for encrypting the files otherwise you will not be able to access them.

  • ← [Fixed] N: Repository ‘ buster/updates InRelease’ changed its ‘Version’ value from ” to ’10’
  • Just for fun: Show gif files as text in Debian Terminal →

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

The Vim editor can be described as a text editor for programmers. It is upward compatible with the Vi editor and can be used to write and edit simple files and programs. Besides the many extensions it offers, the Vim editor can also be used to password protect your text files. In this article, we will explain how to install the Vim editor and then use it to create and open encrypted files. These files can be used for privacy purposes and are only accessible through Vim if you know the password to them.

The commands and procedures mentioned in this article were run on an Ubuntu 22.04 LTS system.

Password protect a file in Vim

Install the Vim Editor

Let us first install the Vim editor on our Ubuntu system. Vim is available on repositories of all major Linux distributors. Open your Linux Terminal either through the system Dash or the Ctrl+Alt+T shortcut. Then enter the following command as root to install the Vim text editor:

The installation procedure requires your confirmation to proceed through a Y/n prompt; enter y in order to continue the installation.

Create a Password Protected File

After the installation is complete, let us proceed with creating a password-protected file. Enter the following command in order to do so:

When you create a text file through the above command, the -x switch indicates that you want to encrypt your file. Therefore, you will be displayed the following message where you can provide an encryption key and then re-confirm it:

When you enter the encryption key and hit enter, a blank file by the specified name will open in the Vim editor. You can insert some text here by first pressing the ‘i’ key. You can then quit and save the file by pressing Esc+wq.

Now, you have successfully created a password-protected text file through the Vim editor.

Open a Password Protected File

If you try to open it through any other text editor, you will see some encrypted characters rather than the text you wrote. For example, we tried to open our file through the Nano editor through the following command:

This is what our encrypted file looks like:

Let us quit and try to open the file through the Vim editor because a file encrypted through Vim can only be opened in Vim.

Enter the following command to open the file:

Since it is a password-protected file, the system will ask you to enter the encryption key.

When you enter the encryption key once and then hit Enter, your file will open in the Vim editor displaying its original contents in decrypted form as follows:

So you have seen how an encrypted file can be created and opened through the Vim editor based on the simple steps described in this article.


Editor teks vim, alat standar yang disertakan di Linux dan macOS, dapat dengan cepat mengenkripsi file teks dengan kata sandi. Lebih cepat dan lebih nyaman daripada mengenkripsi file teks dengan utilitas terpisah. Berikut cara menyiapkannya.

Pastikan Vim Sistem Anda Memiliki Dukungan Enkripsi

Beberapa distribusi Linux, termasuk Ubuntu, menyertakan versi minimal vim secara default, yang ditujukan hanya untuk pengeditan teks dasar. Sebagai contoh, Ubuntu menyebut paket ini “vim-tiny”. Jika Anda mencoba menggunakan enkripsi dalam versi vim yang minimal, Anda akan melihat pesan “Maaf, perintah ini tidak tersedia dalam versi ini”.

Anda mungkin perlu menginstal versi lengkap vim untuk mendapatkan fitur ini pada distribusi Linux Anda. Misalnya, di Ubuntu, Anda bisa mendapatkan versi lengkap vim dengan menjalankan perintah berikut:

sudo apt install vim

Versi vim yang disertakan secara default dengan macOS memang termasuk dukungan enkripsi, jadi Anda tidak perlu menginstal yang lain di Mac. Hanya meluncurkan jendela terminal dari Finder> Aplikasi> Utilitas> Terminal dan perintah akan bekerja sama di macOS seperti yang mereka lakukan di Linux.

Cara Mengenkripsi File Dengan Kata Sandi

Proses dasarnya relatif sederhana jika Anda tahu cara menggunakan vi. Jika tidak, Anda mungkin terpaku pada antarmuka modal vi. Ketika Anda membuka file teks di vim, ada dua mode. Secara default, Anda berada di “mode perintah” di mana Anda dapat menggunakan tombol di keyboard Anda untuk melakukan perintah. Anda juga dapat menekan “i” untuk memasuki “mode Insert”, di mana Anda dapat mengetik secara normal dan menggerakkan kursor di sekitar dengan tombol panah, seperti yang Anda lakukan pada editor teks lainnya. Untuk keluar dari mode insert, tekan “Esc” dan Anda akan kembali ke mode perintah.

Pertama, luncurkan vim. Sebagai contoh, perintah berikut akan meluncurkan vim dan arahkan ke file bernama “example” di direktori saat ini. Jika file itu tidak ada, vim akan membuat file bernama “example” di direktori saat ini ketika Anda menyimpannya:

Anda juga dapat mengarahkan vi pada jalur lain dengan perintah seperti di bawah ini. Anda tidak perlu membuat file di direktori saat ini.

Edit file secara normal. Misalnya, Anda dapat menekan “i” untuk masuk ke mode insert dan kemudian mengetik teks secara normal. Saat mengedit file, tekan Esc untuk memastikan Anda berada dalam mode perintah dan tidak memasukkan mode. Mengetik :X dan tekan Enter.

Anda akan diminta memasukkan kata sandi, yang file teksnya akan dienkripsi. Ketikkan kata sandi yang ingin Anda gunakan, tekan Enter, dan ketik lagi untuk mengonfirmasi. Anda harus memasukkan kata sandi ini kapan saja Anda ingin membuka file di masa mendatang.

Vim akan memperingatkan bahwa Anda menggunakan metode enkripsi yang lemah secara default. Kami akan menunjukkan cara menggunakan metode enkripsi yang lebih aman nantinya.

Kata sandi akan dikaitkan dengan file teks saat ini di Vim, tetapi Anda harus menyimpan perubahan sebelum kata sandi sebenarnya ditetapkan ke file. Untuk melakukan ini, tekan Esc untuk memastikan Anda berada dalam mode perintah, lalu ketikkan :wq dan tekan Enter untuk menulis file ke disk dan keluar dari Vim.

Lain kali Anda mencoba membuka file di Vim — misalnya, dengan menjalankan “ vi example “—Vim akan menanyakan kata sandi yang terkait dengan file tersebut.

Jika Anda memasukkan kata sandi yang salah, isi file akan menjadi omong kosong.

Peringatan: Jangan simpan file jika Anda membukanya dan melihat omong kosong. Ini akan menyimpan data yang rusak kembali ke file dan menimpa data terenkripsi Anda. Lari saja :q untuk keluar dari Vim tanpa menyimpan file ke disk.

Ada satu pintasan lain yang dapat Anda gunakan di sini. Daripada membuat atau membuka file dengan “ vim /path/to/file “, Anda dapat menjalankan perintah berikut untuk membuat atau membuka file dan membuatnya segera meminta Anda untuk mengenkripsi file dengan kata sandi:

vi -x /path/to/file

Perhatikan bahwa Anda perlu menggunakan huruf kecil x di sini, sementara Anda perlu menggunakan X huruf besar saat menjalankan perintah enkripsi terkait dari dalam Vim.

Cara Mengaktifkan Enkripsi yang Lebih Kuat di Vim

Secara default, Vim menggunakan enkripsi yang sangat buruk untuk file-file ini. Metode enkripsi “zip” atau “pkzip” default kompatibel dengan versi 7.2 dan di bawah vim. Sayangnya, ini dapat sangat mudah retak, sangat mudah — bahkan pada perangkat keras dari tahun 90-an. Seperti yang dinyatakan oleh dokumentasi resmi: “Algoritme yang digunakan untuk‘ cryptmethod ’“ zip ”dapat dipecahkan. Kunci 4 karakter dalam waktu sekitar satu jam, kunci 6 karakter dalam satu hari (pada PC Pentium 133). ”

Anda tidak boleh menggunakan enkripsi pkzip untuk dokumen teks Anda jika Anda menginginkan keamanan sama sekali. Namun, Vim menyediakan metode enkripsi yang lebih baik. Versi 7.3 dari Vim dirilis pada tahun 2010 menambahkan metode enkripsi “blowfish”, yang lebih baik. Versi 7.4.399 yang dirilis pada tahun 2014 termasuk metode enkripsi Blowfish baru yang memperbaiki masalah keamanan dalam metode enkripsi “blowfish” asli, dan mengeluarkannya “blowfish2”.

Satu-satunya masalah adalah file yang Anda buat dengan metode enkripsi yang lebih kuat memerlukan versi Vim yang lebih baru. Jadi, jika Anda ingin menggunakan enkripsi “blowfish2”, Anda hanya dapat membuka file itu dengan Vim versi 7.4.399 dan di atasnya. Selama Anda baik-baik saja dengan itu, Anda harus menggunakan metode enkripsi terkuat yang mungkin.

Untuk memeriksa metode enkripsi mana yang digunakan file, buka file dalam vim, tekan tombol Esc untuk memastikan Anda berada dalam mode perintah, ketik perintah berikut, dan tekan Enter.

The “cm” di sini adalah singkatan dari “cryptmethod”.

Anda akan melihat metode enkripsi yang digunakan untuk file saat ini ditampilkan di bagian bawah layar vim.

Untuk memilih metode enkripsi, jalankan salah satu dari perintah berikut. Enkripsi “blowfish2” terbaik untuk keamanan.

:setlocal cm=blowfish2 :setlocal cm=blowfish :setlocal cm=zip

Setelah Anda memilih algoritme enkripsi Anda, gunakan :w perintah untuk menulis file ke disk atau :wq perintah untuk menulis file ke disk dan berhenti.

Saat berikutnya Anda membuka kembali file di Vim, itu tidak akan mengeluh tentang algoritma enkripsi yang lemah. Anda juga akan melihat algoritme enkripsi yang Anda pilih di bagian bawah layar vim saat Anda membuka file.

Cara Mengubah atau Menghapus Kata Sandi

Untuk menghapus kata sandi dari file, buka file itu di Vim dan jalankan :X perintah. Anda akan diminta untuk memberikan kunci enkripsi baru. Masukkan kata sandi baru yang ingin Anda gunakan di sini. Untuk menghapus kata sandi sepenuhnya, biarkan bidang kata sandi kosong dan tekan Enter dua kali.

Simpan file dan berhenti sesudahnya dengan :wq . File akan didekripsi, jadi Anda tidak akan diminta memasukkan kata sandi saat membuka file di masa mendatang.

Pastikan untuk mengingat kata sandi apa pun yang Anda tetapkan atau Anda tidak akan dapat mengakses konten file di masa mendatang.

Textový editor vim, standardní nástroj, který je součástí systému Linux a MacOS, může rychle šifrovat textové soubory heslem. Je to rychlejší a pohodlnější než šifrování textového souboru se samostatným programem.

Ujistěte se, že váš systém Vim má podporu šifrování

Některé linuxové distribuce, včetně Ubuntu, obsahují minimální verzi vim ve výchozím nastavení určenou pouze pro základní úpravy textu. Například Ubuntu nazývá tento balíček “vim-tiny”. Pokud se pokusíte použít šifrování v takové minimální verzi vim, uvidíte zprávu “Omlouvám se, tento příkaz není v této verzi k dispozici”.

Možná bude nutné nainstalovat plnou verzi vim, abyste získali toto funkce v distribuci Linuxu. Například na Ubuntu můžete získat plnou verzi vim spuštěním následujícího příkazu:

Verze vim ve výchozím nastavení s macOS zahrnuje podporu šifrování, takže nemusíte instalovat něco jiného na počítači Mac. Stačí spustit okno terminálu z Finder> Applications> Utilities> Terminal a příkazy budou pracovat stejně jako v MacOS jako v Linuxu.

Jak zašifrovat soubor s heslem

SOUVISEJÍCÍ: Průvodce pro začátečníky k úpravě textových souborů s Vi

Základní proces je poměrně jednoduchý, pokud víte, jak používat vi. Pokud ne, můžete zavěsit na modální rozhraní vi. Když otevřete textový soubor v režimu vim, existují dva režimy. Ve výchozím nastavení se nacházíte v “příkazovém režimu”, kde můžete pomocí kláves na klávesnici provádět příkazy. Můžete také stisknout klávesu “i” pro zadání “Režim vložení”, kde můžete normálně psát a pohybovat kurzorem pomocí kláves se šipkami, stejně jako u jiných textových editorů. Chcete-li opustit režim vložení, stiskněte tlačítko “Esc” a vrátíte se do režimu příkazů.

Nejprve spusťte vim. Například následující příkaz spustí vim a přejde na soubor s názvem “example” v aktuálním adresáři. Pokud tento soubor neexistuje, vytvoří vim při uložení soubor s názvem “example” v aktuálním adresáři:

Můžete také bod vi na jiné cestě s příkazem, jako je níže. V aktuálním adresáři nemusíte vytvářet soubor.

Upravte soubor normálně. Například můžete stisknutím tlačítka “i” vstoupit do režimu vložení a potom zadejte text normálně. Při editaci souboru stiskněte klávesu Esc, abyste se ujistili, že jste v režimu příkazu a ne v režimu vkládání. Zadejte : X a stiskněte klávesu Enter.

Budete vyzváni k zadání hesla, jehož textový soubor bude šifrován. Zadejte heslo, které chcete použít, stiskněte klávesu Enter a znovu jej zadejte pro potvrzení. Budete muset zadat toto heslo kdykoli chcete v budoucnu soubor otevřít.

Vim upozorní, že ve výchozím nastavení používáte slabou šifrovací metodu. Ukážeme vám, jak později použít šifrovací metodu bezpečnější.

Heslo bude přidruženo k aktuálnímu textovému souboru ve formátu Vim, ale změny musíte uložit, než bude heslo skutečně přiřazeno k souboru. Chcete-li to provést, stiskněte klávesu Esc a zadejte příkaz : wq a stiskněte Enter pro zápis souboru na disk a ukončete Vim.

Při příštím pokusu o otevření soubor ve Vimu – např. spuštěním ” vi example ” – Vim vás požádá o heslo spojené se souborem.

Pokud zadáte nesprávné heslo, obsah souboru bude bláznivý

Upozornění : soubor neukládejte, pokud jej otevřete a uvidíte gibberish. Tím se budou poškozená data ukládat zpět do souboru a přepsat šifrované údaje. Jen spusťte : q ukončete Vim bez uložení souboru na disk.

Existuje ještě jedna zkratka, kterou můžete použít zde. Spíše než vytvářet nebo otevírat soubor s ” vim / path / to / file “, můžete spustit následující příkaz, aby vim vytvořil nebo otevřel soubor a okamžitě vás vyzve k zašifrování souboru heslo:

Všimněte si, že zde musíte použít malé písmeno x, zatímco při spuštění přidruženého příkazu šifrování zevnitř Vim musíte použít velkou písmenu X.

Jak povolit silnější šifrování ve formátu Vim

Ve výchozím nastavení používá Vim pro tyto soubory velmi špatné šifrování. Výchozí metoda šifrování “zip” nebo “pkzip” je zpětně kompatibilní s verzemi 7.2 a níže vim. Bohužel to může být velmi, velmi snadno – dokonce i na hardwaru od 90. let. Jak uvádí oficiální dokumentace: “Algoritmus použitý pro” cryptmethod ” zip “je rozbitný. Tlačítko se čtyřmi znaky v délce přibližně jedné hodiny, 6-ti znakové tlačítko v jednom dni (na počítači Pentium 133).

Pokud chcete zabezpečení, vůbec nepoužívejte šifrování pkzip pro vaše textové dokumenty. Vim však poskytuje lepší šifrovací metody. Verze 7.3 vydané Vimu v roce 2010 přidala šifrovací metodu “blowfish”, což je lepší. Verze 7.4.399, která byla vydána v roce 2014, obsahovala novou metodu šifrování Blowfish, která řeší problémy s bezpečností v původní šifrovací metodě “blowfish” a kopíruje ji “blowfish2”.

Jediným problémem je, že soubory, které vytváříte pomocí silnějších metod šifrování, vyžadují tyto novější verze Vim. Pokud tedy chcete použít šifrování “blowfish2”, můžete tento soubor otevřít pouze s verzemi Vim 7.4.399 a vyšším. Pokud je to v pořádku, měli byste použít nejsilnější metodu šifrování

Chcete-li zjistit, který způsob šifrování soubor používá, otevřete soubor v vim, stiskněte klávesu Esc, abyste se ujistili, že jste v příkazovém režimu , zadejte následující příkaz a stiskněte klávesu Enter

“cm” zde znamená “cryptmethod”.

Zobrazí se metoda šifrování použitá pro aktuální soubor zobrazený v dolní části obrazovky vim.

Chcete-li zvolit metodu šifrování, spusťte jeden z následujících příkazů. Šifrování “blowfish2” je nejlepší pro zabezpečení

Jakmile zvolíte šifrovací algoritmus, použijte : w : wq pro zápis souboru na disk a ukončení. Při příštím otevření souboru ve Vimu nebude stěžovat na slabý šifrovací algoritmus. Během otevření souboru uvidíte také šifrovací algoritmus, který jste vybrali v dolní části obrazovky vim.

Jak změnit nebo odstranit heslo

Chcete-li heslo odstranit ze souboru, otevřete soubor ve složce Vim a spusťte příkaz

: X . Budete vyzváni k zadání nového šifrovacího klíče. Zadejte nové heslo, které chcete použít zde. Chcete-li heslo zcela odstranit, ponechte prázdné pole s heslem a stiskněte klávesu Enter dvakrát. Uložte soubor a poté ukončete

: wq . Soubor bude dešifrován, takže při otevření souboru nebudete vyzváni k zadání hesla. Ujistěte se, že jste si zapamatovali heslo, které nastavíte, nebo nebudete mít přístup k obsahu v budoucnosti.

Hej, víte, že aplikace Hudba Google Play, která je dodávána s telefonem Android, se může přihlásit k odběru, streamovat a stahovat podcasty? Funkce funguje v pořádku, i když ne tak skoro jako všichni různí specializovaní správci podcastů. Pokud však nenávidíte mít na svém telefonu další aplikace a už jste nadšený uživatel služby Hudba Play, může to být pro vás to pravý krok.

S Rogue One vychází tento víkend, internet je v plném rozsahu Star Wars , více než obvykle). Proč to nepoužíváte pro zábavu v Photoshopu? Podívejme se na to, jak přidat fotku ke speciálnímu efektu světelného meče. Chci udržet vše co nejjednodušší, ačkoli budete muset postupovat dál, budete muset pochopit vrstvy, masky hladin a vrstvy úprav.

I want to start a private journal on my Mac, but I want to make sure that the file can only be opened by me.

How can I put password security on my file without it slowing down my computer?

6 Answers 6

You could put it in an encrypted disk image.

You can create an encrypted disk image in Disk Utility:

  1. Open Disk Utility.
  2. Go to File > New Image > Blank Image ( Cmd + N ).
  3. Enter a filename, and choose a location. You can also choose the size of the disk image. Make sure to set Encryption to either 128 or 256 bit AES encryption (256 bit is more secure than 128 bit, but it’s also slower.) You can keep all other settings the same.
  4. Enter a passphrase for your disk image.
  5. Ensure you have read/write disk image selected for Image Format (otherwise you won’t be able to write to it)
  6. You can now create the image. Once it’s created, the disk image will be mounted. Copy the files you want to keep safe to the new disk.
  7. Once you’re done, eject the disk by dragging it to the Trash.

Now, whenever you want to access your encrypted files, just mount the image from wherever you saved it to earlier. Once you’re done with your files, eject it as described earlier.

You can encrypt any (individual) file using OpenSSL through Terminal. This is very useful if you are planning on doing a journal in a Word Document, or even a TextEdit file where it’s just one long document. The benefit here is that it’s lightening fast as you are only encrypting/decrypting a single file.

So, let’s assume that on your Desktop we have your Journal conveniently named Journal.txt

To encrypt the file, in Terminal issue the command (assuming “Apple123” is your username):

You will be asked to type and verify a password to encrypt the file. When it’s finished, you will see the new file on your desktop. It will look like a regular text file but when you double click on it, you will get an error message that it cannot be opened.

To decrypt the file, just issue the command:

You will again be asked for the password; enter the one you used to encrypt it. Now, this time, when you double click on the file, you will be able to open your file.

What do those things mean?

enc – Use encryption cipher

-aes-256-cbc – Type of cipher to be used. AES256 is an industry standard.

-e or -d – Encrypt or Decrypt

-in – specifies the full path to the input file

-out – specifies the full path to the output file.

You can obtain more info about OpenSSL by typing man openssl from the Terminal prompt.

Use OpenSSL to encrypt/decrypt.

Encryption: openssl enc -aes-256-cbc -e -in [input path/file] -out [output path/file]

Decryption: openssl enc -aes-256-cbc -d -in [input path/file] -out [output path/file]

Remember your password and make a backup of the file. If you lose/forget the password you are going to be up the creek without a paddle.

Sometimes you may want to password protect folders & directories in Linux, in case you need to store sensitive information in them. Such protection secures these folders from unauthorized access even if they get access to your computer. Cryptkeeper is a simple app that manages encrypted folders. In this article, we will look at how to password protect folders in Linux.

How to Password Protect Folders in Linux

Here are the steps to password protect folders in Linux.

1. Install Cryptkeeper

Open terminal and run the following command to install cryptkeeper in Linux.



Please note, cryptkeeper is available only until Ubuntu 18.04. From Ubuntu 20.04 onwards, it is a part of GNOME EncFS.

2. Open Cryptkeeper

Depending on your Linux distribution, follow these steps to open cryptkeeper.


Go to Applications → System Tools → Cryptkeeper to launch Cryptkeeper.


Go to Applications → System Tools → Cryptkeeper to launch Cryptkeeper.

Sometimes it may not be visible in system tray due to whitelisting policy. In such cases, open terminal and run the following command to open systray whitelist policy.

You will see the following output.

Run the following command to add Cryptkeeper to systray whitelist.

3. Encrypt Folder with CryptKeeper

Once it is started, Cryptkeeper will be visible on system tray on top right/bottom right corner. Click on its icon and choose ‘New encrypted folder’ to create new encrypted folder.

Choose the folder by typing its name or navigating to it.

Enter password and confirm it. Click on Forward button to proceed. It will encrypt your folder.

To open folder, just click its name from Cryptkeeper icon.

In this article, we have learnt how to password protect folder using cryptkeeper.

Tax time is here and many of us will be sharing sensitive information from our financial institutions with our accountants. If there was ever a time to vigilant with securing your private data, this would the moment! Here’s how you can create a compressed zip file with your sensitive data and password protect it on natively macOS.

Prep your files

Since we’ll be using the terminal application that is native on macOS, you’ll want to make the compression of your files as simple as possible to avoid long strings of commands. So if you have multiple files for compressing and protecting, you can organize them into a single folder using Finder.

    Open Finder.

Option-click the Finder window and create a New Folder.

  • Rename the folder, preferably something without spaces as this will make terminal commands simpler for you.
  • Drag and drop your sensitive files into the new folder.
  • Once you have your files in the generated folder, you can now go on to the business of compressing and password protecting the files. Note that if you are e-mailing files, most e-mail providers have a limit on attachment sizes. Secondly, some companies disallow the reception of compressed files via e-mail due to people unknowingly opening malware and as such, your attachment may get stripped and the e-mail server. You’ll need another method to transfer your files such as via Dropbox.

    The terminal

    Since Finder doesn’t have a native password protection option, we’ll have to go deeper under the skin of macOS and straight up a terminal window.

    1. Using Spotlight, type in terminal.
    2. Change your directory to the location of your folder. For example, in my instance that would be to type cd /Volumes/dataMAC and hit enter.
    3. Type in ls to make certain you see your folder.
    4. Now type in the command that will simultaneously compress and password protect the files in the form of zip -er FILESorFOLDERStoCOMPRESS.
    5. In my example that would be zip -er ForTaxes/.
    6. Hit return/enter.

    Next, you’ll be prompted with a password prompt. Type in the password you want to use to protect the files. Enter the password twice.

    Enter your password.

  • The file will be uncompressed into the same directory.
  • Final comments

    This compression and password protection is agnostic to the desktop operating system so you can send it to Window users, Linux users and of course Mac users. Let us know what other ways you use compression and password protection of your files on macOS in the comments.

    This one underrated iOS 16 feature will keep you occupied all day

    iOS 16 will bring a ton of big new features this fall. However, this one feature in particular is already proving to be a favorite of mine, and is a good sign of what could be coming in the future.

    iPadOS 16’s best features only work with M1 iPads and that’s a huge problem

    When Apple announced iPadOS 16’s newest multitasking features were reserved for M1 iPads only, it left a really bad taste in my mouth.

    Here are our favorite features coming to Apple Watch in watchOS 9

    The newest Apple Watch software — watchOS 9 — will bring several new features to the platform; here are the most important ones.

    The best cases you can buy for the 16-inch MacBook Pro right now

    Brand new 16-inch MacBook Pro? You’ll undoubtedly want some protection for it. Here are some of our favorite cases available right now.

    Account Information

    Share with Your Friends

    How to encrypt compressed files the easy way from Windows, macOS, or Linux

    How to encrypt compressed files the easy way from Windows, macOS, or Linux

    Learn to secure multiple documents by encrypting compressed files on various OSes using a password.

    Image: Meilun, Getty Images/iStockphoto

    Must-read security coverage

    • Best encryption software 2022
    • The 10 best antivirus products you should consider for your business
    • 8 enterprise password managers and the companies that will love them
    • Security incident response: Critical steps for cyberattack recovery (TechRepublic Premium)

    When considering how to share data efficiently, cloud storage has a leg up on hardware by making it easy to share files and folders with users across the globe with a few clicks. Because the data is only transmitted from server to client provides little impact on bandwidth for the sender and recipient. But storing data on the cloud is not the most secure practice since that data is effectively placed in the hands of a third party.

    This is especially true of data that is sensitive or confidential in nature. The trade-off is that this type of data should be shared directly between those who require access to it and no one else. By using compressed file types, such as ZIP, a sender can place multiple documents, including entire directories, together and compress them as a single file making it easy to share, while using strong algorithms to encrypt the contents based on a password that only the recipients will know.

    While this technology has existed for decades, modern OSes typically focus on cloud-based sharing services when providing options for users to share data. But that native functionality is present in Windows, macOS, and Linux, and can be accessed simply by entering a few commands into the CLI. Follow below as we go over the steps to perform this on each platform.

    Linux and macOS

    1. Launch the Terminal.
    2. Change directories to where you want the compressed file saved to.
    3. Enter the following command using the -e switch to encrypt the resulting compressed file and -r to recurse subdirectories (if available):
    4. Enter the password when prompted, then again to verify.
    5. The resulting ZIP file will be saved to the chosen directory once the command has completed processing.


    Windows supports creating compressed files via PowerShell from v5.0+, however, while it natively supports ZIP creation it does not support encryption and has a file limit of just 2GB. In the interest of simplicity and for the purposes of this article, I recommend leveraging the 7-zip module for PowerShell to get around these limitations.

    1. Launch PowerShell with administrative escalation.
    2. Install the 7-zip module by entering the cmdlet below. It does query the PS gallery and uses a third-party repository to download the dependencies. If you’re OK with the security considerations, approve the installation to proceed:
    3. Change directories to where you want the compressed file saved.
    4. Create a secure string for your compressed file’s encryption by entering the cmdlet below:
    5. Enter the password you wish to use in PowerShell. The password will be obfuscated by asterisks. The plain text entered will be converted to $SecuresString, and you’ll use that in the next step.
    6. Enter the following cmdlet to encrypt the resulting compressed file:
    7. The resulting ZIP file will be saved to the chosen directory once the command has completed processing.

    Best of the Week Newsletter

    Our editors highlight the TechRepublic articles, downloads, and galleries that you cannot miss to stay current on the latest IT news, innovations, and tips.

    OpenSSL is a powerful cryptography toolkit that can be used for encryption of files and messages.

    If you want to use the same password for both encryption of plaintext and decryption of ciphertext, then you have to use a method that is known as symmetric-key algorithm.

    From this article you’ll learn how to encrypt and decrypt files and messages with a password from the Linux command line, using OpenSSL.

    HowTo: Encrypt a File

    Options Description
    openssl OpenSSL command line tool
    enc Encoding with Ciphers
    -aes-256-cbc The encryption cipher to be used
    -salt Adds strength to the encryption
    -in Specifies the input file
    -out Specifies the output file.

    Interesting fact: 256bit AES is what the United States government uses to encrypt information at the Top Secret level.

    Warning: The -salt option should ALWAYS be used if the key is being derived from a password.

    Without the -salt option it is possible to perform efficient dictionary attacks on the password and to attack stream cipher encrypted data.

    The reason for this is that without the salt the same password always generates the same encryption key.

    When the salt is being used the first eight bytes of the encrypted data are reserved for the salt: it is generated at random when encrypting a file and read from the encrypted file when it is decrypted.

    HowTo: Decrypt a File

    Options Description
    -d Decrypts data
    -in Specifies the data to decrypt
    -out Specifies the file to put the decrypted data in

    Base64 Encode & Decode

    Base64 encoding is a standard method for converting 8-bit binary information into a limited subset of ASCII characters.

    It is needed for safe transport through e-mail systems, and other systems that are not 8-bit safe.

    By default the encrypted file is in a binary format.

    If you are going to send it by email, IRC, etc. you have to save encrypted file in Base64-encode.

    Cool Tip: Want to keep safe your private data? Create a password protected ZIP file from the Linux command line. Really easy! Read more →

    To encrypt file in Base64-encode, you should add -a option:

    Option Description
    -a Tells OpenSSL that the encrypted data is in Base64-ensode

    Option -a should also be added while decryption:

    Non Interactive Encrypt & Decrypt

    Warning: Since the password is visible, this form should only be used where security is not important.

    By default a user is prompted to enter the password.

    If you are creating a BASH script, you may want to set the password in non interactive way, using -k option.

    Cool Tip: Need to improve security of the Linux system? Encrypt DNS traffic and get the protection from DNS spoofing! Read more →

    Public key cryptography was invented just for such cases.

    Encrypt a file using a supplied password:

    Decrypt a file using a supplied password:

    20 Replies to “Encrypt & Decrypt Files With Password Using OpenSSL”

    I have used the last command line to decrypt a file but my lecturer hinted that I need to use a parameter related to encoding. What is it? The code is base64.

    if I understand your question correctly you need to add -a to your command for input in base64 format

    Thanks! That was super helpful.

    with -k password it is showing “error in input file”

    sintax to decript a message

    im trying to decrypt without specifying the file name as i want to do a whole folder and decrypt an encrypted folder via bash script.

    it gives an error message
    error:20074002:BIO routines:FILE_CTRL:system lib:bss_file.c:400:

    Help would be appreciated!

    I encrypted a .dmg file using openssl encryption on my Macbook Pro, keeping the output name the same as the input name. I didn’t know this would be problematic, as I am now unable to decrypt the .dmg file even with the correct password.

    Some folks say it could not be done, but it seemed to have worked for me. Now, I can’t open the file and am afraid it will be impossible to decrypt.

    Note: If I use the same code, but change the output name, it can decrypt just fine. My issue was that I encrypted the file using the same output name as the input, which has made it impossible for me to decrypt it.

    Here’s what the code looks like:
    openssl enc -aes-256-cbc -d -in /Users/huntert/Desktop/IMPT.dmg -out /Users/huntert/Desktop/IMPT.dmg
    enter aes-256-cbc encryption password:
    Verifying – enter aes-256-cbc encryption password:

    When I tried to decrypt it, I received the folllowing messages:
    enter aes-256-cbc decryption password:
    error reading input file

    I should’ve been more cautious and tried it on a rubbish file. Lesson learned.

    Hello, the option to give the password is
    -pass pass:
    -pass file:
    works for ecoding & decoding

    I have a problem to decrypt a file
    I have encrypted my file after I used this file in matlab (modulation ..) and then I cannot decrypt the extracted file from matlab
    error is ” error reading file ”
    what I have to do ?

    thank you for this, very helpful.
    one thing I ask, where do I get the openssl (I assume executable) from to run the encrypt and decrypt?

    Hello, how are you? I have an encrypted file which I forgot the password, it is a file (.evp), what command line do I get to decrypted it?

    I’m tring to find out if will possible to decrypt a directory with a certificate private with open SSL.
    If you want a solution i’m here

    Hello Thanks for this article.
    But how do we do this programmatically? I’ve a situation where I need to use a password to login to a server programmatically. We cannot hard code the password to decrypt the file. One option I know is to store the password in a vault but that takes too long/expensive to implement. Please suggest. thanks