linux下文件加密操作记录
时间:2022-04-23
本文章向大家介绍linux下文件加密操作记录,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
为了安全考虑,通常会对一些重要文件进行加密备份或加密保存,下面对linux下的文件加密方法做一简单介绍:
一、 ZIP加密 1)文件加密 使用命令"zip -e filename.zip filename" 即可出现输入密码的提示,输入2次密码。 此文件即被加密解压时候是需要密码的
下面开始为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次密码。 此文件即被加密解压时候是需要密码的。
下面开始对目录进行加密
[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只能对文件进行加密,对目录则无法完成加密!
下面开始使用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!!!
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 一起来玩玩WebGL
- 自研网关:多项目的swagger聚合功能
- Prometheus 如何做到“活学活用”,大牛总结的避坑指南
- 文档驱动 —— 表单组件(一):表单元素组件 优点缺点选择文本类的Inputcheck 多选value的类型问题
- Vue3.0源码结构分析
- 【每周一库】- cached - 缓存结构型、辅助函数记忆化
- meta生成器 —— 表单元素组件 meta表单代码meta的模板data变幻
- 不用写代码也能做表单 —— 加载meta即可 菜单表单加载json运行效果。ModelAbout
- 从0到1,手把手教你入门 etcd
- 数据结构:手把手带你了解 ”图“ 所有知识!(含DFS、BFS)
- 设计模式之单例模式
- AndroidStudio创建JNI 工程与调用
- Java 版植物大战僵尸思路和源码分享!
- 你好MyBatis 入门篇
- 你好MyBatis 中级篇