I'm trying to write a script to automate an rclone process that requires ssh authentication via public key with a passphrase for the private key. The authentication service does not run by default in a new session. Manually I can do
$ eval `ssh-agent`
Agent pid 2335
$ ssh-add
Enter passphrase for /home/user/.ssh/private_key:
Identity added: /home/user/.ssh/private_key (/home/user/.ssh/private_key)
and then I run the rclone process. However, if I run the script, let's call it auth
#!/bin/bash
eval `ssh-agent`
/path/to/scpw
where scpw is an expect script that automates the passphrase input for ssh-add, then I get the same output as manual entry:
$ /path/to/auth
Agent pid 2335
Enter passphrase for /home/user/.ssh/private_key:
Identity added: /home/user/.ssh/private_key (/home/user/.ssh/private_key)
but when I try to run the rclone process now, I get the error message
yyyy/mm/dd hh:mm:ss Failed to create file system for "computer:directory": couldn't
connect to ssh-agent: SSH agent requested but SSH_AUTH_SOCK not-specified
which is the same error message I get if I didn't run ssh-add at all. I tried several variants such as
eval `ssh-agent` && ssh-add
eval `ssh-agent` && sleep 3 && ssh-add`
eval `ssh-agent` && /path/to/scpw (where scpw waits 3 seconds to enter passphrase)
all of which also worked manually but didn't work in script. I'm pretty baffled.