是否可以使用 scrypt 命令加密文件夹中的所有文件?

是否可以使用 scrypt 命令加密文件夹中的所有文件?

我已经尝试使用 scrypt 加密单个文件,而且似乎效果很好。

但是如果我想加密文件夹中的所有文件该怎么办?

根据手册页,scrypt 是一种加密文件的工具。

还有办法加密文件夹中的所有文件吗?

答案1

可以用来encfs加密文件夹:

方法 1:

  1. 安装:

    sudo apt install encfs
    
  2. 创建所需的目录,一个用于存储加密数据,另一个用于访问加密数据:

    encfs ~/.encrypt ~/visible
    
  3. 接受所提出的请求,encfs然后为其设置一个您喜欢的密码。

  4. 现在将要保护的文件放在~/visible文件夹中。

  5. 要隐藏它们,请运行:

    fusermount -u ~/visible
    
    # This will hide all files in there.
    
  6. 要再次访问它们,请运行:

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

来源:

https://help.ubuntu.com/community/FolderEncryption

方法 2:

使用Gnome Encfs Manager

  1. 安装:

    sudo add-apt-repository ppa:gencfsm 
    sudo apt update 
    sudo apt install gnome-encfs-manager
    
  2. 运行该Gnome Encfs Manager程序以使用 GUI 实现与方法 1 相同的功能。

方法 3:

您可以使用终端脚本scrypt来实现此目的:

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

更多信息:

  1. koko:我的想象文件夹,你的应该有所不同
  2. 每次加密后你都必须输入密码

方法 4

对于写入文件的随机生成的密码:

#!/bin/bash

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

else

    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
        echo 
        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
        esac
    else
        mkdir /home/$USER/Documents/"$passwdlocation"
    fi  

    # 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
                echo
                case "$doagain" in
                    y|Y)  rm -rf "/home/$USER/Documents/"$passwdlocation"/"$mypasswords".txt";;
                    n|N)  echo "file not deleted!";;
                    *) echo "Operation successful";;
                esac
        else

        fi

        for i in "$folder"/*
        do
            # 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"
        done

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

        exit 1

    fi  


    else

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

    fi

fi

echo "Script finished"

相关内容