linux下文件加密操作记录

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

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

下面开始为test.txt文件进行加密
[[email protected] ~]# cat test.txt
this is a test!!!
[[email protected] ~]# zip -e test.txt.zip test.txt         //如下进行加密操作时,需要输入两次密码
Enter password:
Verify password:
  adding: test.txt (stored 0%)
[[email protected] ~]# ls
test.txt  test.txt.zip

进行解压的时候,需要输入密码
[[email protected] ~]# rm -f test.txt
[[email protected] ~]# unzip test.txt.zip
Archive:  test.txt.zip
[test.txt.zip] test.txt password:
 extracting: test.txt
[[email protected] ~]# cat test.txt
this is a test!!!

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

下面开始对目录进行加密
[[email protected] ~]# mkdir dirtest
[[email protected] ~]# cat dirtest/haha.txt
this is test of dir!!!
[[email protected] ~]# zip -re dirtest.zip dirtest
Enter password:
Verify password:
  adding: dirtest/ (stored 0%)
  adding: dirtest/haha.txt (stored 0%)

解压目录时需要输入密码
[[email protected] ~]# rm -rf dirtest
[[email protected] ~]# unzip dirtest.zip
Archive:  dirtest.zip
   creating: dirtest/
[dirtest.zip] dirtest/haha.txt password:
 extracting: dirtest/haha.txt
[[email protected] ~]# ls dirtest
haha.txt
[[email protected] ~]# 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只能对文件进行加密,对目录则无法完成加密!

下面开始使用GnuPG方式对test.txt文件进行加密
[[email protected] ~]# cat test.txt
this is a test!!!
[[email protected] ~]# gpg -c test.txt
can‘t connect to `/root/.gnupg/S.gpg-agent‘: No such file or directory         //这个信息可以忽略

注意:如上加密的时候,会要求Paraphrase输入两次密码,对这个特定的文件进行加密。

一旦运行带-c选项(完全使用对称密码算法加密)的gpc命令,它会生成一个文件.gpg文件。
[[email protected] ~]# 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

对文件进行加密后,最好将源文件删除!不要再保留源文件了!
[[email protected] ~]# rm -f test.txt

文件解密操作。
注意出现Paraphrase提示时,需要提供加密时输入的同一个密码才能解密
[[email protected] ~]# 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
[[email protected] ~]# 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
[[email protected] ~]# cat test.txt
this is a test!!!

原文地址:https://www.cnblogs.com/kevingrace/p/8194784.html

时间: 2024-08-09 14:27:34

linux下文件加密操作记录的相关文章

linux下监控用户操作记录的工具

linux下监控用户操作记录的工具: apt-get install bsdutils mkdir /opt/operation_log chmod 777 -R /opt/operation_log vi /etc/profile exec script -t 2> /opt/operation_log/$USER-$UID-date +%F-%T.data -a -q -f /opt/operation_log/$USER-$UID-date +%F-%T.log :wq source /e

linux下文件加密方法总结

为了安全考虑,通常会对一些重要文件进行加密备份或加密保存,下面对linux下的文件加密方法做一简单总结: 方法一:gzexe加密这种加密方式不是非常保险的方法,但是能够满足一般的加密用途,可以隐蔽脚本中的密码等信息.它是使用系统自带的gzexe程序,它不但加密,同时压缩文件.示例如下: 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 29 30 31 32 33 34 35 36 37 38 3

linux下文件加密压缩和解压的方法

一.用tar命令 对文件加密压缩和解压 压缩:tar -zcf  - filename |openssl des3 -salt -k password | dd of=filename.des3 此命令对filename文件进行加码压缩 生成filename.des3加密压缩文件, password 为加密的密码. 解压:dd if=filename.des3 |openssl des3 -d -k password | tar zxf - 注意命令最后面的“-”  它将释放所有文件, -k p

linux 下文件加密压缩和解压的方法

方法一:用tar命令 对文件加密压缩和解压 压缩: [html] view plain copytar -zcf - filename |openssl des3 -salt -k password | dd of=filename.des3 此命令对filename文件进行加码压缩 生成filename.des3加密压缩文件, password 为加密的密码 解压: [html] view plain copydd if=filename.des3 |openssl des3 -d -k pa

linux下文件的读写操作(openreadwrite)

linux下文件的读写操作(openreadwrite) 转 http://www.2cto.com/os/201403/285837.html open(打开文件) 相关函数 read,write,fcntl,close,link,stat,umask,unlink,fopen 表头文件 #include<sys/types.h>#include<sys/stat.h>#include<fcntl.h> 定义函数 int open( const char * path

【大话QT之五】Windows与Linux下文件操作监控的实现

一.需求分析: 随着渲染业务的不断进行,数据传输渐渐成为影响业务时间最大的因素.究其原因就是因为数据传输耗费较长的时间.于是,依托于渲染业务的网盘开发逐渐成为迫切需要解决的需求.该网盘的实现和当前市场上网盘实现有一些的不同,主要在客户端与服务器端的操作需要双向进行,即:用户在客户端的操作需要及时同步到服务器端:在服务器端作业渲染生成的文件要及时同步到客户端.即:用户不在需要单独的下载数据,而是在作业运行的同时,渲染就过就会自动同步到客户端,大大缩短了等待时间.当然,无论是在客户端还是在服务端都面

Windows与Linux下文件操作监控的实现

一.需求分析: 随着渲染业务的不断进行,数据传输渐渐成为影响业务时间最大的因素.究其原因就是因为数据传输耗费较长的时间.于是,依托于渲染业务的网盘开发逐渐成为迫切需要解决的需求.该网盘的实现和当前市场上网盘实现有一些的不同,主要在客户端与服务器端的操作需要双向进行,即:用户在客户端的操作需要及时同步到服务器端:在服务器端作业渲染生成的文件要及时同步到客户端.即:用户不在需要单独的下载数据,而是在作业运行的同时,渲染就过就会自动同步到客户端,大大缩短了等待时间.当然,无论是在客户端还是在服务端都面

(转)linux下文件删除的原理精华讲解(考试题答案系列)

linux下文件删除的原理精华讲解(考试题答案系列) 说明:本文为老男孩linux培训某节课前考试试题及答案分享博文内容的一部分,也是独立成题的,你可以点下面地址查看全部的内容信息.http://oldboy.blog.51cto.com/2561410/791245 5.描述linux下文件删除的原理(记时3分钟)<?xml:namespace prefix="o"> ?xml:namespace> Linux文件删除原理:     Linux是通过link的数量来

linux下的安全操作

Linux下的安全操作,使用前要备份 Cd /etc/yum.repos.d/ Ls 改名 cp Centos-Base.repo Centos-Base.repo.ori Ori代表的原始文件 Wget(获取网址下载) :http://...../Centos-Base-163.repo Ls 替换原来的Base Cp CentOS-Base-163.repo CentOS-Base.repo 替换原来的Base Yum grouplist 查看包组,装了那些包 SELINUX是美国安全局对于