Shell Script To Encrypt Any Text File

in Categories File-management, Security last updated September 14, 2008

In cryptography, encryption is the process of transforming information (referred to as plaintext) using an algorithm (called cipher) to make it unreadable to anyone except those possessing special knowledge, usually referred to as a key.

Mcrypt is a simple crypting program, a replacement for the old unix crypt(1). When encrypting or decrypting a file, a new file is created with the extension .nc and mode 0600. The new file keeps the modification date of the original. The original file may be deleted by specifying the -u parameter. If no files are specified, the standard input is encrypted to the standard output.

Sample Shell Script Wrapper To Encrypt Any Text File

# Write a shell script to encrypt any text file
# -------------------------------------------------------------------------
# Copyright (c) 2001 nixCraft project <>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit for more information.
# -------------------------------------------------------------------------
echo -n "Enter a file name : "
read file
if [ ! -f $file ]
	echo "$file not a file!"
	exit 1
echo -n "Enter a Password : "
read password
# do encryption using UNIX crypt command
# this command will prompt for a password
crypt $password < $file > $file.cpy
echo  "$file.cpy created as encrypted file"

Share this on:

6 comment

  1. can u please give me a script file for squid server configuration,
    in which the user have the privilege to input the access list.
    pleease upload it soon.

Leave a Comment