I'm having a problem using the gpg-agent over ssh via a single command line.
Here is my configuration :
Server A : triggering the command via ssh.
ssh user@serverB "sudo -E /path/to/script.sh"
Server B : Executing the script requiring a passphrase signature.
System info : Ubuntu 12.04
I've setup the gpg-agent on the server B, I've added this configuration to the /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
Here is the configuration of the agent in /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
So in order to make this works, I connect to the serverB via ssh :
ssh user@serverB
The gpg-agent is started, I trigger manually the script:
sudo -E /path/to/script.sh
Then, the gpg-agent prompt me asking for a passphrase, once I've setup the passphrase, I can run the script again, and it's doing its task without asking for a passhprase.
My problem is, when I try to trigger it distantly, e.g. via :
ssh user@serverB "sudo -E /path/to/script.sh"
It seems that the gpg-agent is not working, because the script keeps asking me for a passphrase.
Edit:
I've added the following content to /etc/sudoers.d/user in order to trigger the script distantly without the sudo password and to keep the environment variables :
user ALL=(ALL)NOPASSWD:SETENV:/path/to/script.sh
Any ideas?