微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ubuntu – 在ssh上使用gpg-agent

我通过单个命令行在ssh上使用gpg-agent时遇到问题.

这是我的配置:

服务器A:通过ssh触发命令.

ssh user@serverB "sudo -E /path/to/script.sh"

服务器B:执行需要密码短语签名的脚本.

系统信息:Ubuntu 12.04

我在服务器B上设置了gpg-agent,我已将此配置添加到/home/user/.bashrc:

Invoke GnuPG-Agent the first time we login.                                                                          
# Does `~/.gpg-agent-info' exist and points to gpg-agent process accepting signals?                                    
if test -f $HOME/.gpg-agent-info && \
    kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info` 2>/dev/null; then
    GPG_AGENT_INFO=`cat $HOME/.gpg-agent-info | cut -c 16-`
else
    # No,gpg-agent not available; start gpg-agent                                                                     
    eval `gpg-agent --daemon --write-env-file $HOME/.gpg-agent-info`
fi
export GPG_TTY=`tty`
export GPG_AGENT_INFO

以下是/home/user/.gnupg/gpg-agent.conf中代理的配置:

enable-ssh-support
#1 year cache support
default-cache-ttl 31536000
default-cache-ttl-ssh 31536000
max-cache-ttl 31536000
max-cache-ttl-ssh 31536000
#debug-all

所以为了使这个工作,我通过ssh连接到serverB:

ssh user@serverB

gpg-agent启动,我手动触发脚本:

sudo -E /path/to/script.sh

然后,gpg-agent提示我要求密码,一旦我设置了密码,我就可以再次运行脚本,并且它正在执行其任务而不需要传递密码.

我的问题是,当我试图远程触发时,例如,途经:

ssh user@serverB "sudo -E /path/to/script.sh"

似乎gpg-agent无法正常工作,因为脚本一直在问我一个密码短语.

编辑:

我已将以下内容添加到/etc/sudoers.d/user,以便在没有sudo密码的情况下远程触发脚本并保留环境变量:

user ALL=(ALL)nopASSWD:SETENV:/path/to/script.sh

有任何想法吗?

当您使用ssh user @ serverB登录然后手动执行脚本时,它将首次提示您输入密码,然后当您执行脚本时,shh-agent将提供存储的密码短语.

但是当你运行ssh user @ serverB“sudo -E /path/to/script.sh时,你每次都在进行新的登录,我不认为ssh-agent会支持在单独的SSH登录中保存密码.

钥匙串似乎可以满足您的需求:http://www.funtoo.org/Keychain

With keychain,you only need to enter a passphrase once every time your local machine is rebooted. Keychain also makes it easy for remote cron jobs to securely “hook in” to a long running ssh-agent process,allowing your scripts to take advantage of key-based logins.

The current version of keychain supports gpg-agent as well as ssh-agent.

原文地址:https://www.jb51.cc/ubuntu/348850.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐