mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Merge pull request #4620 from OneNewLife/master
[Translated by OneNewLife]20160806 How to Encrypt and Decrypt Files and Directories Using Tar and OpenSSL.md
This commit is contained in:
commit
db45cbf532
@ -1,77 +0,0 @@
|
||||
OneNewLife translating
|
||||
|
||||
# How to Encrypt and Decrypt Files and Directories Using Tar and OpenSSL
|
||||
|
||||
When you have important sensitive data, then its crucial to have an extra layer of security to your files and directories, specially when you need to transmit the data with others over a network.
|
||||
|
||||
That’s the reason, I am looking for a utility to encrypt and decrypt certain files and directories in Linux, luckily I found a solution that tar with OpenSSL can do the trick, yes with the help of these two tools you can easily create and encrypt tar archive file without any hassle.
|
||||
|
||||
In this article, we will see how to create and encrypt a tar or gz (gzip) archive file with OpenSSL:
|
||||
|
||||
Remember that the conventional form of using OpenSSL is:
|
||||
|
||||
```
|
||||
# openssl command command-options arguments
|
||||
|
||||
```
|
||||
|
||||
#### Encrypt Files in Linux
|
||||
|
||||
To encrypt the contents of the current working directory (depending on the size of the files, this may take a while):
|
||||
|
||||
```
|
||||
# tar -czf - * | openssl enc -e -aes256 -out secured.tar.gz
|
||||
|
||||
```
|
||||
|
||||
Explanation of the above command:
|
||||
|
||||
1. `enc` – openssl command to encode with ciphers
|
||||
2. `-e` – a enc command option to encrypt the input file, which in this case is the output of the tar command
|
||||
3. `-aes256` – the encryption cipher
|
||||
4. `-out` – enc option used to specify the name of the out filename, secured.tar.gz
|
||||
|
||||
#### Decrypt Files in Linux
|
||||
|
||||
To decrypt a tar archive contents, use the following command.
|
||||
|
||||
```
|
||||
# openssl enc -d -aes256 -in secured.tar.gz | tar xz -C test
|
||||
|
||||
```
|
||||
|
||||
Explanation of the above command:
|
||||
|
||||
1. `-d` – used to decrypt the files
|
||||
2. `-C` – extract in subdirectory named test
|
||||
|
||||
The following image shows the encryption process and what happens when you try to:
|
||||
|
||||
1. extract the contents of the tarball the traditional way
|
||||
2. use the wrong password, and
|
||||
3. when you enter the right password
|
||||
|
||||
[![Encrypt or Decrypt Tar Archive File in Linux](http://www.tecmint.com/wp-content/uploads/2016/08/Encrypt-Decrypt-Tar-Archive-Files-in-Linux.png)][1]
|
||||
|
||||
Encrypt or Decrypt Tar Archive File in Linux
|
||||
|
||||
When you are working on a local network or the Internet, you can always secure your vital documents or files that you share with others by encrypting them, this can help reduce the risk of exposing them to malicious attackers.
|
||||
|
||||
We looked at a simple technique of encrypting tarballs using OpenSSL, a openssl command line tool. You can refer to its man page for more information and useful commands.
|
||||
|
||||
As usual, for any additional thoughts or simple tips that you wish to share with us, use the feedback form below and in the upcoming tip, we shall look at a way of translating rwx permissions into octal form.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/encrypt-decrypt-files-tar-openssl-linux/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+tecmint+%28Tecmint%3A+Linux+Howto%27s+Guide%29
|
||||
|
||||
作者:[Gabriel Cánepa][a]
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: http://www.tecmint.com/author/gacanepa/
|
||||
[1]:http://www.tecmint.com/wp-content/uploads/2016/08/Encrypt-Decrypt-Tar-Archive-Files-in-Linux.png
|
@ -0,0 +1,75 @@
|
||||
OneNewLife translated
|
||||
|
||||
# 怎样用 Tar 和 OpenSSL 给文件和目录加密及解密
|
||||
|
||||
当你有重要的隐私数据的时候,给你的文件和目录额外加一层保护是至关重要的,特别是当你需要通过网络与他人传输数据的时候。
|
||||
|
||||
这就是为什么我正在寻找一个实用程序在 Linux 上加密及解密文件和目录,幸运的是我找到了一个用 tar(Linux 的一个压缩打包工具)和 OpenSSL 来解决的方案。借助这两个工具,你真的可以毫不费力地创建和加密 tar 归档文件。
|
||||
|
||||
在这篇文章中,我们将了解如何使用 OpenSSL 创建和加密 tar 或 gz(gzip,另一种压缩文件)归档文件:
|
||||
|
||||
牢记使用 OpenSSL 的常规方式是:
|
||||
|
||||
```
|
||||
# openssl command command-options arguments
|
||||
|
||||
```
|
||||
|
||||
#### 在 Linux 中加密文件
|
||||
|
||||
要加密当前工作目录的内容(根据文件的大小,这可能需要一点时间):
|
||||
|
||||
```
|
||||
# tar -czf - * | openssl enc -e -aes256 -out secured.tar.gz
|
||||
|
||||
```
|
||||
|
||||
上述命令的解释:
|
||||
|
||||
1. `enc` - openssl 命令使用密码进行编码
|
||||
2. `-e` – 用来加密输入文件的 enc 命令选项,这里是 tar 命令的输出
|
||||
3. `-aes256` – 加密用的算法
|
||||
4. `-out` – 用于指定输出文件名的 enc 选项,这里文件名是 `secured.tar.gz`
|
||||
|
||||
#### 在 Linux 中解密文件
|
||||
|
||||
要解密 tar 归档内容,使用以下命令。
|
||||
|
||||
```
|
||||
# openssl enc -d -aes256 -in secured.tar.gz | tar xz -C test
|
||||
|
||||
```
|
||||
|
||||
上述命令的解释:
|
||||
|
||||
1. `-d` – 用于解密文件的选项
|
||||
2. `-C` – 提取内容到 `test` 子目录
|
||||
|
||||
下图展示了加密过程,以及当你尝试执行以下操作时会发生什么:
|
||||
|
||||
1. 以传统方式提取 tar 包的内容
|
||||
2. 使用了错误的密码的时候
|
||||
3. 当你输入正确的密码的时候
|
||||
|
||||
[![在 Linux 中加密和解密 Tar 归档文件](http://www.tecmint.com/wp-content/uploads/2016/08/Encrypt-Decrypt-Tar-Archive-Files-in-Linux.png)][1]
|
||||
|
||||
在 Linux 中加密和解密 Tar 归档文件
|
||||
|
||||
当你在本地网络或因特网工作的时候,你可以随时通过加密来保护你和他人共享的重要文本或文件,这有助于降低将其暴露给恶意攻击者的风险。
|
||||
|
||||
我们研究了一种使用 OpenSSL(一个 openssl 命令行工具)加密 tar 包的简单技术,你可以参考它的手册页(man page)来获取更多信息和有用的命令。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/encrypt-decrypt-files-tar-openssl-linux/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+tecmint+%28Tecmint%3A+Linux+Howto%27s+Guide%29
|
||||
|
||||
作者:[Gabriel Cánepa][a]
|
||||
|
||||
译者:[OneNewLife](https://github.com/OneNewLife)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: http://www.tecmint.com/author/gacanepa/
|
||||
[1]:http://www.tecmint.com/wp-content/uploads/2016/08/Encrypt-Decrypt-Tar-Archive-Files-in-Linux.png
|
Loading…
Reference in New Issue
Block a user