Skip to content
  • About Us
  • Contact Us
  • Privacy Policy
  • Disclaimer
  • Corona Virus Stats (Covid-19)
  • Work with us
  • FB
  • LinkedIn
  • Twitter
  • Instagram.com
Tekraze

Tekraze

Dive Into Technology

  • Guides
    • Developer Guide
    • PC Guide
    • Web Guide
    • Android Guide
    • Music
    • Tutorials
  • Feed
    • Tech News
    • Shared Tech
    • Gaming Videos
    • Unboxing videos
  • Forums
    • Android Apps
    • Angular Npm Packages
    • Useful Site Links
    • Tech Queries
    • Windows OS Help
    • Web Guide and Help
    • Android Os And Rooting
    • Jhipster Discussion
    • Git & GitHub forum
    • Open Source Forum
  • Work with us
  • Toggle search form
How to Encrypt Decrypt Files in Linux Tekraze

How to Encrypt and Decrypt Files in Linux

Posted on September 1, 2018 By Balvinder Singh 10 Comments on How to Encrypt and Decrypt Files in Linux

Linux makes it easy to encrypt and decrypt files using the “gpg” utility that’s included by default in just about every installation. The package is an open source implementation of a tool previously used by Symantec, and which has even received a chunk of funding from the German government.

In this article, I’ll show you a few quick commands to easily encrypt a file using a passphrase.

Table of Contents

  • Encrypting Files
  • What to Do with the Encrypted File?
  • Decrypting the File
  • Using More Secure Encryption Methods

Encrypting Files

“GNU Privacy Guard” is the full form of “gpg“, and you can get started with encrypting files immediately. In this screenshot for example, I have a sample file with some random content:

secret file encryption tekraze

I can encrypt it using the following command:

gpg -c myfile.txt

This will open up a dialogue box asking for a password. Once you enter the password, you’ll be asked to retype it again to confirm:

passphrase tekraze

That’s it. You’re done! If you look at the original location of the file, you’ll now see another file with the “.gpg” extension like this:

encrypted file tekraze

This contains the encrypted data. You can verify this by opening it and taking a look at the contents as shown above. The output is nothing but junk.

| Also Read | Top Linux Distros 2018

What to Do with the Encrypted File?

Once you have both the original and the encrypted file, you have two options:

  1. Either delete the original from your hard disk
  2. Mail the encrypted file to someone else

The first is so that you can hide sensitive data on your own personal system. The second option is to be able to send someone the encrypted version of the file in a secure manner without anyone looking at it. It’s a great way to share sensitive information.

You need to communicate the passphrase that you generated in the first step. This can be over an unrelated medium like the phone for example. Obviously you don’t want to use the same channel over which you send the encrypted file!

| Also Read | Terminology Basics you need to know

Decrypting the File

Once you have the encrypted file in your hands, it’s time to decrypt it. You can do this using the following command:

gpg -d myfile.text.gpg

However, if you run this command on your own system immediately after encrypting the file, gpg won’t ask you for the password and the contents will be displayed on the screen like this:

showing without password tekraze

This is because the “gpg-agent” process has cached the password you just used and won’t ask you for it again in a certain time frame. We can temporarily bypass this by reloading the agent like this:

echo RELOADAGENT | gpg-connect-agent

This time, it asks you for  the password when you try and decrypt:

Asking for password to decrypt tekraze

You can make behavior permanent by editing this file:

~/.gnupg/gpg-agent.conf

And adding the following lines:

default-cache-ttl 1
max-cache-ttl 1

This sets the expiry of the cache to 1 second.

Note that the decryption dumps the file data onto the screen. If you want, you can send the output to a file using the “-o” parameter as shown here:

gpg -o newfile.txt -d myfile.txt.gpg

| Also Read | Types of Programming Difference you need to Know

Using More Secure Encryption Methods

In the screenshots above, you might have noticed the following message while decrypting:

WARNING: Message was not integrity protected

This means that gpg cannot be sure that the encrypted file has not been tampered with. It’s because by default, gpg uses an older CAST5 encryption protocol. However, newer encryption methods have since been devised that protect against file tampering. The AES protocol for example, is much more secure.

We can force gpg to use 256-bit AES encryption with the following parameter:

--cipher-algo AES256

So the encryption command becomes:

gpg --cipher-algo AES256 -c myfile.txt

This time when we decrypt, we no longer get the warning:

no longer warning tekraze

Even more secure would be to sign the file with your keypair. But that’s for another tutorial!

How to Encrypt and Decrypt Files in Linux 2

 

 

This post is a Guest from Jeff Wilson from Linux Host Support

Jeff Wilson is a senior Linux system administrator at LinuxHostSupport, a premium server management company that focus on Linux server administration.

 

If anyone of readers want to share a guest post, he can also do via link Guest-posting Link . Stay connected for more updates coming up next. This one was well 99th post of our blog, We will be starting something new from our 100th post , so stay connected and keep checking.

Content Protection by DMCA.com
Tutorials, Developer Guide, PC Guide Tags:decryption, encryption, files, linux, security

Post navigation

Previous Post: Google Map JSON Parser
Next Post: Startups changing cleantech 🔌

Related Posts

  • Jekyll - A Beginners Guide to static website 4
    Jekyll – A Beginners Guide to static website Tutorials
  • The Open Source OS Linux 5
    The Open Source OS Linux Developer Guide
  • The Skills and Equipment you’ll need to be a Kickass Developer Tekraze
    The Skills and Equipment you’ll need to be a Kickass Developer Guest posts
  • MarkUp editor
    MarkUp Editor – A new editor in Town Tech News
  • How to Google Search Like A pro
    How to Google Search Like a Pro you must know Web Guide
  • Photoshop Basics Tutorials 6
    Photoshop Basics Tutorials Web Guide

Comments (10) on “How to Encrypt and Decrypt Files in Linux”

  1. Domitila says:
    May 3, 2020 at 10:18 pm

    Attractive section of content. I just stumbled upon your blog and in accession capital to assert that I acquire in fact enjoyed account your blog posts. Anyway I’ll be subscribing to your feeds and even I achievement you access consistently fast.|

    Reply
    1. Balvinder Singh says:
      May 4, 2020 at 10:53 am

      Thanks

      Reply
  2. Roberto says:
    May 4, 2020 at 3:58 am

    Hey there, You’ve done an incredible job. I’ll certainly digg it and personally recommend to my friends. I’m confident they’ll be benefited from this website.|

    Reply
    1. Balvinder Singh says:
      May 4, 2020 at 10:52 am

      Thanks

      Reply
  3. Stevie says:
    May 4, 2020 at 4:07 am

    Hi there to every one, the contents existing at this website are genuinely remarkable for people knowledge, well, keep up the nice work fellows.|

    Reply
    1. Balvinder Singh says:
      May 4, 2020 at 10:52 am

      Thanks

      Reply
  4. Collen says:
    May 9, 2020 at 6:17 am

    Hi there! Someone in my Myspace group shared this site with us so I came to check it out. I’m definitely loving the information. I’m book-marking and will be tweeting this to my followers! Fantastic blog and fantastic design.|

    Reply
    1. Balvinder Singh says:
      May 10, 2020 at 1:43 pm

      Thanks

      Reply
  5. Larisa says:
    May 9, 2020 at 6:26 am

    You actually make it seem so easy with your presentation however I in finding this topic to be actually something which I think I’d by no means understand. It seems too complex and very extensive for me. I am taking a look ahead for your subsequent put up, I will attempt to get the hold of it!|

    Reply
    1. Balvinder Singh says:
      May 10, 2020 at 1:42 pm

      Thanks, keep visiting

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Advertisements

Subscribe to updates

Enter your email below to subscribe





Posts by Categories

Advertisements
  • Brave Browser Feature Image
    Brave Browser Be Brave to say no to ads and secure privacy Web Guide
  • ADD AWS Transcribe to Spring Boot APP Tekraze
    Add AWS Transcribe to Spring boot App Developer Guide
  • eBook Reader Apps for Android Devices Banner
    Top 5 eBook Reader Apps for Android Devices Android Guide
  • Merging Multiple PDF files online
    7 Online PDF Tools That Help You Merge Files Web Guide
  • Tekraze Plural Sight courses
    Learn with Plural – Learn with Google Tutorials
  • How to get a chinese phone number banner
    How to Get a Chinese Phone Number? Web Guide
  • Workspace monitoring and surveillance with Ethical Sky App Tekraze
    Workplace monitoring with Ethical Spy App Android Guide
  • The Importance of a Virtual Number for Registration | OnlineSim
    The Importance of a Virtual Number for Registration | OnlineSim Web Guide

Affliate Links

Sell with Payhip

Earn with Magenet

Sell and Buy with Adsy

GainRock affiliate Program

Automatic Backlinks

Advertise with Anonymous Ads

accessily tekraze verificationIndian Blog Directory

Copyright © 2023 Tekraze.

Powered by PressBook News WordPress theme