UNIX File Encryption howto

Q. I’m using UNIX (FreeBSD) at work. I need to encrypt a file. What command I need to type?

A. You need to use crypt command which provides very simple file encryption. It works under UNIX, BSD, Linux and possible all other UNIX like oses.

Itis a very simple encryption program, working on a secret-key basis. It operates as a filter, i.e., it encrypts or decrypts a stream of data from standard input, and writes the result to standard output. Since its operation is fully symmetrical, feeding the encrypted data stream again through the engine (using the same secret key) will decrypt it.

Task: Encrypt the original file called my.txt

Type the command as follows:
$ cat my.txt | crypt > my.cpy

Enter key:

This will create an encrypted form of my.txt file, and store it in the file my.cpy.

Task: Ensure that the file is encrypted

Type the following command:
$ cat my.cpy

Task: Decrypt the file called my.txt

Type the command as follows:
$ cat my.cpy | crypt > my.file.txt

Under FreeBSD you can use enigma (same command with different name – the crypt utility, also known as enigma), to displays the previously created file on the terminal:
$ enigma PASSWORD

Also note that many new UNIX oses comes with mcrypt command. It is intended to be a replacement of the old unix crypt under the GNU General Public License.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • mike Apr 17, 2007 @ 13:25

    Note that the crypt command is notoriously weak. Use ccrypt and its associated commands instead. It uses AES encryption and is far stronger.

  • Tofig Jul 6, 2008 @ 6:09

    I would prefer using gnupg which is available from FreeBSd ports.

  • Praveen Thati Oct 1, 2009 @ 11:30

    when we given this command we got the error as cryptcommand not found. But in the start of the page you given as this cmd can be used for all UNIX OS.

    So i did not get any help from this site.

    Thank you and hope the things will be with clear data in this site from this day onwards.

    Thank you for considering the feedback.

  • pratik Mar 19, 2012 @ 7:28

    I have tried to call this command
    cat my.txt | crypt > my.cpy
    but error is showing that this command is not in my system ..

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum