리눅스에서 파일이나 디렉토리를 암호화하는 방법? 터미널의 파일 또는 디렉토리 암호화와 같은 작업을

Linux에서 터미널의 파일 또는 디렉토리 암호화와 같은 작업을 수행하는 가장 인기있는 명령은 무엇입니까?



답변

나는 그것이 gpg 일 것이라고 생각합니다. 파일과 디렉토리의 구문은 다릅니다.

암호화

파일의 경우 (outputs filename.gpg) :

gpg -c filename

dirs의 경우 :

gpg-zip -c -o file.gpg dirname

복호화

파일의 경우 (outputs filename.gpg) :

gpg filename.gpg

dirs의 경우 :

gpg-zip -d file.gpg

편집 : @ Mk12가 암호화 / 암호 해독에 대한 압축 / 압축 해제의 실수를 지적했을 때 수정되었습니다.


답변

  • openssl과 함께

openssl des3 -salt -in unencrypted-data.tar -out encrypted-data.tar.des3

해독 :

openssl des3 -d -salt -in encrypted-data.tar.des3 -out unencrypted-data.tar

  • AES로 암호화

aescrypt -e -p password file.jpg

해독 :

aescrypt -d -p password file.jpg.aes


답변

GnuPG를 사용해보십시오 .

암호화하려면 gpg -c filename

해독하려면 gpg filename.gpg


답변

이것은 openssl과 tar를 사용하는 방법입니다.

암호화 된 디렉토리를 엽니 다.

openssl enc -aes-256-cbc -d -in ~/vault.tar.gz.dat | tar xz; thunar ~/vault

암호화 된 디렉토리 잠금 :

tar cz vault/ | openssl enc -aes-256-cbc -out ~/vault.tar.gz.dat; rm -r ~/vault


답변

나는 개인적으로 aescrypt주로 사용 합니다.

      aescrypt -e "File"

해독 :

      aescrypt -d "File"

또는 mcrypt가 있습니다.

      mcrypt "File"

해독 :

      mcrypt -d "File"

그리고 디렉토리의 경우 디렉토리를 tar하고 암호화하는 것이 좋습니다. 그런 다음 암호화를 해제 한 후 파일을 untar하십시오.

      tar -cf "Dir.tar" Dir/

그리고 untar

      tar -xf "Dir.tar"


답변

최고 수준의 보안이 큰 문제가 아닌 경우 (zip의 맨 페이지에서 zipfile 유틸리티가 사용하는 암호화 알고리즘이 PGP보다 약하다고 말하면) zip 및 unzip을 선호합니다. 내 디렉토리를 압축하고 동시에 암호화합니다. 압축을 선호하고 전체를 다시 압축하고 암호화하는 대신 증분 압축 및 암호화를 사용할 수 있기 때문에 zip을 선호합니다. 특히 디렉토리 크기가 매우 큰 경우에 유용합니다.

ZIP 및 암호화

zip file.zip file
zip -r directory.zip directory
zip --encrypt file.zip.enc file # prompt for password
zip --encrypt -r directory.zip.enc directory # prompt for password

압축 해제 및 암호 해독

unzip directory.zip.enc #Beware if any directory is present with the same name as the zipped file, then it would be overwritten. Hence I normally send the contents to another directory.

unzip directory.zip.enc -d directory-new # prompts for password


답변

인기가 없지만 몇 가지 Bash 스크립트를 사용하여 최소한의 사용자 상호 작용으로 아무것도 암호화 / 암호 해독하는 프로젝트를 진행하고 있습니다. 다음 은 테스트 설정을 설명 하는 Hak5 게시물에 대한 링크 입니다.

소스 코드 로직을 통한 절단 위의 링크 된 프로젝트에서 처리 할 수있는 각 유형의 데이터에 대해 어떻게됩니까?

_gnupg_encrypt_opts="--always-trust --armor --batch --encrypt --recipient user@host.domain"
 _bulk_output_dir="some_path"
_arbitrary_parsed_output="some_file.gpg"
## If file make encrypted time stamped file with similar name
_path_to_file="${_mapped_input}"
_path_to_output="${_bulk_output_dir}/$(date -u +%s)_${_path_to_file##*/}.gpg"
cat "${_path_to_file}" | gpg ${gpg _gnupg_encrypt_opts} > "${_path_to_output}"
## else if directory make compressed encrypted time stamped output file
_path_to_dir="${_mapped_input}"
_path_to_output="${_bulk_output_dir}/$(date -u +%s)_dir.tgz.gpg
tar -cz - "${_path_to_dir}" | gpg ${gpg _gnupg_encrypt_opts} > "${_path_to_output}"
## else if something else append encrypted output to file
_path_to_output="${_arbitrary_parsed_output}"
cat <<<"${_mapped_input}" | gpg ${gpg _gnupg_encrypt_opts} >> "${_path_to_output}"

${_mapped_input}변수는 읽기가 설정 mkfifo명명 된 파이프 파일과 함께 배열로 읽는 모든 설정 mapfile -t _lines < "${_file_to_map}"이후 확장과에 저장되어있는 ${_mapped_input}… 조금 뒤얽힌하지만 실험적인 기능은 각각의 라인에 따라 행동하는 것이 허용합니다. 최종 결과는 암호화 된 파일 또는 압축 된 디렉토리를 보유하기위한 디렉토리와 다양한 암호화 된 데이터 패킷이있는 파일로 끝납니다.

암호화에 사용 된 공개 키와 관련된 개인 키가있는 장치에서는 파일 또는 압축 된 디렉토리의 암호 해독이 간단합니다. 그러나 여러 갑옷으로 암호화 된 데이터 패킷의 암호 해독은 조금 더 어려웠으므로 Paranoid_Pipes_Scenario_One.sh위의 프로젝트에서 명명 된 스크립트 는 최소한의 사용자 상호 작용으로 모든 것을 수행하도록 작성되었습니다. 다음은 일반적인 암호화 된 파일 및 디렉토리에 대한 헬퍼 스크립트 소스 코드의 단순화 된 버전입니다.

_gnupg_decrypt_opts="--quiet --no-tty --always-trust --passphrase-fd 9 --decrypt"
_decryption_output_dir="some_directory"
# if file
exec 9<"${_pass[@]}"
_path_to_file="${_mapped_input}"
_output_name="${_path_to_file##*/}"
_output_name="${_output_name%.gpg*}"
cat "${_path_to_file}" | gpg ${_gnupg_decrypt_opts} > "${_decryption_output_dir}/${_output_name}"
# else if compressed file
_path_to_file="${_mapped_input}"
_output_name="${_path_to_file##*/}"
_output_name="${_output_name%.tgz.gpg*}"
mkdir -p "${_decryption_output_dir}/${_output_name}"
_old_pwd="${PWD}"
cd "${_decryption_output_dir}/${_output_name}"
cat "${_path_to_file}" | gpg ${_gnupg_decrypt_opts} | tar -xzf -
cd "${_old_pwd}"
# else if non-compressed directory
_path_to_file="${_mapped_input}"
_output_name="${_path_to_file##*/}"
_output_name="${_output_name%.tar.gpg*}"
mkdir -p "${_decryption_output_dir}/${_output_name}"
_old_pwd="${PWD}"
cd "${_decryption_output_dir}/${_output_name}"
cat "${_path_to_file}" | gpg ${_gnupg_decrypt_opts} | tar -xf -
cd "${_old_pwd}"

다른 기능이 작동하고 공개적으로 검증 가능한 방식으로 테스트되고 싶은 경우 Travis-CI 빌드 로그 (특히 로그 끝 근처) 를 확인하면 관련하여 진행중인 다른 멋진 것들이 있습니다. 거의 모든 데이터의 암호화 및 해독