0

I'm trying to persist an ssh tunnel connection with Remote port forwarding to access a machine behind a home router, using a cron job, as shown in this blog: https://juliansimioni.com/blog/howto-access-a-linux-machine-behind-a-home-router-with-ssh-tunnels/

Problem is my vpn has an identity file with password to connect to ssh. I can only connect at terminal typing in password each time. Adding the password via ssh-agent , ssh-add didnt work for cron job. How to get cron job to use the ssh-agent for current user?

1
  • 1
    For an automated process, I'd be inclined create a key without a passphrase, and configure the server to limit what command(s) the key can be used for.
    – Kenster
    Feb 25, 2023 at 21:59

1 Answer 1

0

First:

ssh-agent > ~/.ssh/.ssh-agentrc
ssh-add
<enter your passcode when prompted>

Then in your script:

. ~/.ssh/.ssh-agentrc

Hey presto - your key is available in your script's environment!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .