linux下文件加密操作记录

本文涉及的产品
密钥管理服务KMS,1000个密钥,100个凭据,1个月
简介:

为了安全考虑,通常会对一些重要文件进行加密备份或加密保存,下面对linux下的文件加密方法做一简单介绍:

一、 ZIP加密
1)文件加密
使用命令"zip -e filename.zip filename" 即可出现输入密码的提示,输入2次密码。 此文件即被加密解压时候是需要密码的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
下面开始为 test .txt文件进行加密
[root@centos6-vm02 ~] # cat test.txt
this is a  test !!!
[root@centos6-vm02 ~] # zip -e test.txt.zip test.txt         //如下进行加密操作时,需要输入两次密码
Enter password:                          
Verify password:
   adding:  test .txt (stored 0%)
[root@centos6-vm02 ~] # ls
test .txt   test .txt.zip
 
进行解压的时候,需要输入密码
[root@centos6-vm02 ~] # rm -f test.txt
[root@centos6-vm02 ~] # unzip test.txt.zip
Archive:   test .txt.zip
[ test .txt.zip]  test .txt password:
  extracting:  test .txt               
[root@centos6-vm02 ~] # cat test.txt
this is a  test !!!

2)文件夹加密
使用命令"zip -re dirname.zip dirname"即可出现输入密码的提示,输入2次密码。 此文件即被加密解压时候是需要密码的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
下面开始对目录进行加密
[root@centos6-vm02 ~] # mkdir dirtest
[root@centos6-vm02 ~] # cat dirtest/haha.txt
this is  test  of  dir !!!
[root@centos6-vm02 ~] # zip -re dirtest.zip dirtest
Enter password:
Verify password:
   adding: dirtest/ (stored 0%)
   adding: dirtest /haha .txt (stored 0%)
 
解压目录时需要输入密码
[root@centos6-vm02 ~] # rm -rf dirtest
[root@centos6-vm02 ~] # unzip dirtest.zip
Archive:  dirtest.zip
    creating: dirtest/
[dirtest.zip] dirtest /haha .txt password:
  extracting: dirtest /haha .txt       
[root@centos6-vm02 ~] # ls dirtest
haha.txt
[root@centos6-vm02 ~] # cat dirtest/haha.txt
this is  test  of  dir !!!

二、GnuPG加密
GnuPG的全称是GNU隐私保护(GNU Privacy Guard),常常被称为GPG,它结合了一组加密软件。它是由GNU项目用C编程语言编写的。最新的稳定版本是2.0.27。在如今的大多数Linux发行版中,gnupg程序包都是默认随带的,所以万一它没有安装,你可以使用apt或yum从软件库来安装它(yum install gnupg)。注意:gpg只能对文件进行加密,对目录则无法完成加密!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
下面开始使用GnuPG方式对 test .txt文件进行加密
[root@centos6-vm02 ~] # cat test.txt
this is a  test !!!
[root@centos6-vm02 ~] # gpg -c test.txt   
can 't connect to `/root/.gnupg/S.gpg-agent' : No such  file  or directory          // 这个信息可以忽略
 
注意:如上加密的时候,会要求Paraphrase输入两次密码,对这个特定的文件进行加密。
 
一旦运行带-c选项(完全使用对称密码算法加密)的gpc命令,它会生成一个文件.gpg文件。
[root@centos6-vm02 ~] # ll test.txt*
-rw-r--r--. 1 root root 18 Jan  4 10:08  test .txt
-rw-r--r--. 1 root root 61 Jan  4 10:04  test .txt.gpg
 
对文件进行加密后,最好将源文件删除!不要再保留源文件了!
[root@centos6-vm02 ~] # rm -f test.txt
 
文件解密操作。
注意出现Paraphrase提示时,需要提供加密时输入的同一个密码才能解密
[root@centos6-vm02 ~] # gpg test.txt.gpg  
gpg: 3DES encrypted data
can 't connect to `/root/.gnupg/S.gpg-agent' : No such  file  or directory
gpg: encrypted with 1 passphrase
gpg: WARNING: message was not integrity protected
[root@centos6-vm02 ~] # ll test.txt*
-rw-r--r--. 1 root root 18 Jan  4 10:08  test .txt
-rw-r--r--. 1 root root 61 Jan  4 10:04  test .txt.gpg
[root@centos6-vm02 ~] # cat test.txt
this is a  test !!!
***************当你发现自己的才华撑不起野心时,就请安静下来学习吧***************

本文转自散尽浮华博客园博客,原文链接:http://www.cnblogs.com/kevingrace/p/8194784.html,如需转载请自行联系原作者
相关文章
|
3月前
|
网络协议 Linux 网络安全
入职必会-开发环境搭建39-Linux常用操作-Linux防火墙操作
在CentOS 7中,新引入了firewalld服务(防火墙),取代了CentOS 6之前的iptables服务(防火墙)。
入职必会-开发环境搭建39-Linux常用操作-Linux防火墙操作
|
2月前
|
存储 算法 Linux
在Linux中,如何理解加密工具?如GnuPG和OpenSSL。
在Linux中,如何理解加密工具?如GnuPG和OpenSSL。
|
3月前
|
存储 运维 Linux
Linux磁盘精准缩容:操作详解与技巧
在Linux系统管理中,有效的磁盘空间优化对于维护系统性能至关重要。本文将深入探讨如何在Linux环境下安全地进行磁盘缩容,帮助你合理调整存储资源,确保系统高效运行。跟随本篇的步骤,一起优化你的Linux系统磁盘空间!
Linux磁盘精准缩容:操作详解与技巧
|
2月前
|
存储 安全 Linux
Linux存储安全:数据加密的实践与策略
【8月更文挑战第19天】数据加密是Linux存储安全的基石之一。通过使用LUKS进行磁盘加密和使用GnuPG进行文件加密,可以显著提高数据的安全性。
53 0
|
4月前
|
Linux 网络安全 开发工具
Linux 管理远程会话 screen:掌握终端的多任务操作
`Linux screen` 命令让多任务管理变得更简单,尤其在SSH连接远程服务器时。创建新会话如`screen -S backup`,查看会话`screen -ls`,退出`exit`。高级功能包括直接在会话中运行命令,如`screen vim memo.txt`,会话共享以协同工作,以及通过`screen -r`或`-D -r`重新连接或强制恢复断开的会话。提高效率,确保任务不间断运行。
55 1
|
4月前
|
JavaScript 前端开发 安全
安全开发-JS应用&原生开发&JQuery库&Ajax技术&加密编码库&断点调试&逆向分析&元素属性操作
安全开发-JS应用&原生开发&JQuery库&Ajax技术&加密编码库&断点调试&逆向分析&元素属性操作
|
3月前
|
安全 固态存储 Linux
服务器linux操作系统重装的完整流程-傻瓜式教学
服务器linux操作系统重装的完整流程-傻瓜式教学
|
4月前
|
Linux 应用服务中间件 网络安全
linux 初始化全部操作
linux 初始化全部操作
30 1
|
5月前
|
分布式计算 Hadoop Linux
实验: 熟悉常用的Linux操作和Hadoop操作
实验: 熟悉常用的Linux操作和Hadoop操作
57 2
|
4月前
|
Linux C++
Linux C/C++目录和文件的更多操作
Linux C/C++目录和文件的更多操作
下一篇
无影云桌面