I have already tried using scrypt for encrypting single files and it seems to be working quite well.

But what if I want to encrypt all the files in a folder?

According to man page scrypt is a tool for encrypting files.

Is there still a way to encrypt all the files in a folder?

  • Are you referring to encrypting the folder or each file individually? – George Udosen May 22 '17 at 8:38

One can use encfs to encrypt a folder:

Method 1:

  1. Install it:

    sudo apt install encfs
  2. Create the required directories, one for the encrypted data and the other for accessing them:

    encfs ~/.encrypt ~/visible
  3. Accept the requests made by encfs then give it a password of your liking.

  4. Now place the files to protect in the ~/visible folder.

  5. To hide them run:

    fusermount -u ~/visible
    # This will hide all files in there.
  6. To access them again run:

    encfs ~/.encrypted ~/visible
    # This will ask you for your password so the files
    # in ~/visible will be seen and accessed



Method 2:

Use Gnome Encfs Manager

  1. Install:

    sudo add-apt-repository ppa:gencfsm 
    sudo apt update 
    sudo apt install gnome-encfs-manager
  2. To use run the Gnome Encfs Manager program to use GUI to achieve the same as in method 1.

Method 3:

Using a terminal script you can use scrypt to achieve this:

for i in /home/$USER/Documents/koko/*; do scrypt enc "$i" "$i-sc"; done

More information:

  1. koko: My imaginary folder, yours should be different
  2. You will have to enter the password for each encryption done

Method 4

For randomly generated passwords written into a file:


echo "Running script..."
echo " "
echo "Please enter the names of folder to encrypt file contents"
echo "and folder to store the passwords for the files"    
echo " "

read -p 'Files location: ' folder
read -p 'Password storage location: ' passwdlocation
read -p 'name of password file: ' mypasswords
echo " "

if [[ -z "$folder" || -z "$passwdlocation" ]];then

    echo "Please supply the required folder names"
    exit 1


    if [ -d "/home/$USER/Documents/"$passwdlocation"" ]; then

        # If password folder exists ask user if it should be deleted
        read -n1 -p "/home/$USER/Documents/"$passwdlocation" exists, delete Y or N?" doit
        case "$doit" in
            y|Y)    rm -R /home/$USER/Documents/"$passwdlocation" && mkdir /home/$USER/Documents/"$passwdlocation";;
            n|N) echo "Script terminated by user" && exit 1;;
            *) echo
        mkdir /home/$USER/Documents/"$passwdlocation"

    # Is it a directory
    if [[ -d "$folder" ]]; then
        # Make sure target folder has files in it
        if [ ! "$(ls -A "/home/$USER/Documents/"$folder"" 2> /dev/null)" == "" ]; then          

            # Check if password file already exists
            # if it does ask to delete of write to it
            if [ "$( ls -A "/home/$USER/Documents/"$passwdlocation"/"$mypasswords".txt" 2> /dev/null)" == "" ]; then

                read -n1 -p ""$mypasswords".txt already exists, delete Y or N? " doagain
                case "$doagain" in
                    y|Y)  rm -rf "/home/$USER/Documents/"$passwdlocation"/"$mypasswords".txt";;
                    n|N)  echo "file not deleted!";;
                    *) echo "Operation successful";;


        for i in "$folder"/*
            # Create random passwords
            filepasswd=$(strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n';) 

            scrypt enc -P "$i" "$i-sc" <<< "$filepasswd"

            # Add password to password store location
            echo -n  "$i-sc  $filepasswd" >> "/home/$USER/Documents/"$passwdlocation"/"$mypasswords".txt"
            echo -e "\n" >> "/home/$USER/Documents/"$passwdlocation"/"$mypasswords".txt"
            echo "$i Done"

        echo "The target "$folder" is empty!"

        exit 1



        echo "Invalid arguments .. please supply directory names"
        exit 1



echo "Script finished"
  • I have it already only trying to fine tune it... will update shortly – George Udosen May 22 '17 at 12:12
  • Hi George. I noticed the scrypt method in your answer now. I will try it tomorrow if I can and leave some feedback if it works. – Vesa May 22 '17 at 12:22
  • Hi George. I noticed that you are the same cool dude that helped me the last time I asked about scrypt. That time I wanted to use the password from stdin in the one-liner. Now I am trying to combine both one-liners. Like so: for i in koko/*; do scrypt enc -P "$i" "$i-sc" <<< "passtest123"; done. However it doesn't quite seem to be working. When I used only your line it worked but I had to enter the password manually. Can we make this one-liner loop through all the files, encrypt them and also use the password from stdin in the same one-liner? – Vesa May 22 '17 at 12:31
  • Be patient already on it when through will post after testing the script, and the one up there works. The folder has to be in you /home/$USER directory.. stay tuned – George Udosen May 22 '17 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.