Re: using "at" and ssh



Cloud Burst <DoNotReplyViaEmail@xxxxxxxxxxx> wrote:
> So let's say I do this and come back the next day. My job ran fine,
> but now there is this ssh-agent running that I can't use for anything,
> right? According to the ssh-add man page (and I tried) I can't use a
> new ssh-add against this old ssh-agent. I have to start a new agent.

You don't have to start a new agent. You can use the old agent if you
have saved the relevant environment variables in a file so they can be
read by your new shell. A few lines in my .bash_profile do this, along
with a check that the agent still exists:

# Save ssh-agent environment variables in a file
# so that they can be read by processes not inheriting
# this environment; e.g., those started by cron.
# But don't start more than one agent, so check first.
[ -f $HOME/.ssh-agent ] && . $HOME/.ssh-agent
if ! ssh-add -l >/dev/null 2>&1
then
ssh-agent | head -2 >$HOME/.ssh-agent
. $HOME/.ssh-agent
fi

If the data in $HOME/.ssh-agent is stale (i.e., the corresponding agent
is dead), ssh-add will return an error and a new agent will be started.

Scripts (started by cron, for example) just have to read in the
environment variables to be able to contact the agent, with a line
like:

. $HOME/.ssh-agent

(with perhaps a check for a dead agent as above and suitable error
handling).

--
John Wingate Mathematics is the art which teaches
johnww@xxxxxxxxxxxxx one how not to make calculations.
--Oscar Chisini
.



Relevant Pages

  • Re: sshd read environment variable?
    ... > can sshd 2.9 read environment variables for the password? ... > if i automate the distribution of files across servers (yes, ... Have you read about ssh-agent and ssh-add to keep your password's cached? ... Of course then you'll also need ssh-askpass (a X frontend for ssh-add). ...
    (comp.security.ssh)
  • Re: cygwin ssh-add problem
    ... > get the ssh-add going. ... environment variables to be available for ssh-add, ... If you just start ssh-agent from bash, ... This will allow ssh-add (and the ssh client) to work correctly, ...
    (comp.security.ssh)
  • Re: Agent Forwarding Question for the list
    ... ssh-add agent on server1 as well. ... this is the whole purpose of agent forwarding. ... can see the SSH_* environment variables which ssh-agent creates. ... all ssh sessions from all of your xterms will be ...
    (SSH)
  • Re: OpenSSH - cant get passphrase to work
    ... This will be supremely useless. ... It will start an agent, ... ssh-add; you will add a key a to the agent -- and the agent will then ... % eval `ssh-agent` ...
    (comp.security.ssh)
  • Re: Apache Software Foundation Server compromised, resecured. (fwd)
    ... >> originating client hosting the first ssh-agent in a chain. ... >> forward your agent from trusted host A to untrusted host B, ... there is a sshd process on Host_B which is ... you used public keys and did not do agent forwarding, ...
    (FreeBSD-Security)