zl程序教程

您现在的位置是:首页 >  工具

当前栏目

Shell脚本攻略学习笔记十之加密命令

2023-09-14 09:13:15 时间

Shell脚本攻略学习笔记十之加密命令

MD5命令

1.检验整个文件夹的MD5

我们需要安装一个md5deep,然后执行命令:md5deep -rl directory_path > directory.md5

2. 检验单个文件的md5
  • 直接输出到当前控制台
    [root@server4 shells]# md5sum jps.sh 
    85731a19587b898dbacfc5fec42157d4  jps.sh
  • 将加密文件输出到指定文件
[root@server4 shells]# md5sum jps.sh > jps.md5
[root@server4 shells]# cat jps.md5 
85731a19587b898dbacfc5fec42157d4  jps.sh
  • 验证加密文件是否匹配
[root@server4 shells]# md5sum -c jps.md5 
jps.sh: OK

sha命令

[root@server4 shells]# sha   #可以看到有这么多的加密命令
sha1sum    sha224sum  sha256sum  sha384sum  sha512sum  sharesec   
  • 将加密后验证码输入到指定文件中
sha1sum: jps.sha1: No such file or directory
[root@server4 shells]# sha1sum jps.sh > jps.sha1
[root@server4 shells]# cat jps.sh
#!/bin/sh
for HOST in `cat hosts`
do
echo ---------------------
ssh -t root@$HOST "jps"
done
  • 检验加密文件是否正确
[root@server4 shells]# sha1sum -c jps.sha1 
jps.sh: OK

md5sum and SHA-1 are unidirectional hash algorithms, which cannot be reversed to form the original data.