You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Debian系统中Bash备份脚本执行GPG加密命令返回错误码127,但直接Shell执行正常的问题求助

Debian系统中Bash备份脚本执行GPG加密命令返回错误码127,但直接Shell执行正常的问题求助

我正在编写一个用于网站备份的Bash脚本,调用gpg加密备份文件时遇到了棘手的问题:脚本里执行gpg命令会返回错误码127失败,但手动在Shell里执行完全相同的命令却能正常工作。

出错的gpg命令如下:

gpg --homedir /home/backupuser/.gnupg --verbose --no-tty --recipient {group-name} --trust-model always --output /home/backupuser/backup/{tar-file}.gpg --encrypt /mnt/ramdir/site-backup-backupuser/{tar-file}

我已经确认过所有关键路径的状态:

  • gpg的主目录/home/backupuser/.gnupg确实存在
  • 待加密的{tar-file}文件存在于指定路径
  • 输出目录/home/backupuser/backup/已创建,输出文件尚未存在

更奇怪的是,就算在脚本里重复执行这条命令,依然会以同样的方式失败;但脚本执行失败后,我立刻在Shell中输入完全相同的命令,却能顺利完成加密,执行时的输出信息如下:

gpg: using subkey {hhhhhhhhhhhhhhhh} instead of primary key {hhhhhhhhhhhhhhhh}
gpg: automatically retrieved '{email address1}' via Local
gpg: No trust check due to '--trust-model always' option
gpg: using subkey {hhhhhhhhhhhhhhhh} instead of primary key {hhhhhhhhhhhhhhhh}
gpg: automatically retrieved '{email address2}' via Local
gpg: No trust check due to '--trust-model always' option
gpg: reading from '/mnt/ramdir/site-backup-backupuser/{tar-file}'
gpg: writing to '/home/backupuser/backup/{tar-file}.gpg'
gpg: '/mnt/ramdir/site-backup-backupuser/{tar-file}' already compressed
gpg: RSA/AES256 encrypted for: "{hhhhhhhhhhhhhhhh} {Comment} <{email address1}>"
gpg: RSA/AES256 encrypted for: "{hhhhhhhhhhhhhhhh} {Comment} <{email address2}>"

我的系统环境:

  • Debian "bullseye" 11.6
  • gpg 2.2.27
  • libgcrypt 1.8.8

我已经尝试了各种参数组合来排查问题,包括:

  • 保留或移除--homedir参数
  • 尝试用sudo执行命令(当时真的急病乱投医了)
  • 将待加密文件从RAM盘移到本地磁盘
  • 保留或移除--verbose参数
  • 其他几个参数的调整

但所有尝试的结果都一致:脚本内执行返回错误码127,手动Shell执行完全正常。有没有朋友能帮我分析下问题出在哪里?

备注:内容来源于stack exchange,提问作者NigelB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 08:24:08