欧卡2中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

需要三步,才能开始

只需两步,慢速开始

玩欧卡就用莱仕达V10方向盘欧卡2入门方向盘选莱仕达V9莱仕达折叠便携游戏方向盘支架欢迎地图Mod入驻
查看: 3872|回复: 2
收起左侧

[系统维护] 解决gpg加密无法加入到crontab中的问题

[复制链接]
oppo 发表于 2015-3-23 19:37 | 显示全部楼层 |阅读模式
原文:http://knktc.com/2014/05/12/gpg-crontab/
我最近写个每天自动加密文件的shell脚本时才发现,平时在命令行下直接可用的gpg加密语句放到脚本中,再加入到crontab中定时执行可能会失败。研究了下才发现,想在crontab中调用gpg加密还需要两个额外的参数才可以。  

如果是平时在命令行下加密文件,例如给邮件名为test@knktc.com的公钥用户加密一个testfile.txt的文件,那我会使用以下的命令:

gpg -ear test@knktc.com —trust-model always —yes .testfile.txt

本来以为这样的命令写入脚本后再加入到crontab中是没有什么问题的,但几分钟后我却发现加入到crontab中的脚本没有执行gpg加密的功能。对此,上网上查了些资料,发现如果想让cron服务来执行gpg的加密,还需要两个参数: –no-tty和—homedir, 修改完成后的命令应该是:

gpg —homedir=/root/.gnupg —no-tty -ear test@knktc.com —trust-model always —yes .testfile.txt

这样的话,cron在执行定时的加密任务时就可以找到存放公钥的目录,同时也可以在cron自己的环境下完成加密任务了。
 楼主| oppo 发表于 2015-3-24 11:51 | 显示全部楼层
        --no-tty                                    
                                    
        Make sure that the TTY (terminal) is never used for any output. This option is needed in some cases because GnuPG sometimes prints warnings to the TTY if --batch is used.         
                                             
        --batch                                    
                                    
        Use batch mode. Never ask, do not allow interactive commands.         
                                             
        --no-batch                                    
                                    
        Disable batch mode. This may be of use if --batch is enabled from an options file.

http://www.spywarewarrior.com/uiuc/gpg/gpg-com-3.htm
 楼主| oppo 发表于 2015-3-24 11:56 | 显示全部楼层
gpg -aer tianxu --trust-model always --batch --yes data.txt

联系我们|手机版|欧卡2中国 ( 湘ICP备11020288号-1 )

GMT+8, 2024-3-28 19:29 , Processed in 0.034935 second(s), 7 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表