How to automatically add keyfile and passphrase to ssh-agent?
1
vote
2
answers
8697
views
Linux 4.4.0-34-generic #53-Ubuntu SMP Wed Jul 27 16:06:39 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
I use the script to start ssh-agent and start other script (which is using *expect* to sent passphrase to agent).
#!/bin/bash
eval
ssh-agent -s
/root/script2
**/root/script2:**
#!/usr/bin/expect -f
spawn ssh-add /root/.ssh/key
expect "Enter passphrase for /root/.ssh/key:"
send "passphrase\n";
interact
All scripts are +x
Passphrase is valid 100%
After starting first script I get:
Agent pid 3985
spawn ssh-add /root/.ssh/key
Enter passphrase for /root/.ssh/key:
Identity added: /root/.ssh/key (/root/.ssh/key)
As you see, *agent started* and *Identity added* BUT when I try "*ssh-add -l*" I get:
Error connecting to agent: No such file or directory
But process is still working with 3985 PID.
Why it tells me *Identity added* but *ssh-add -l* didn't work? :(
Ok, I try manually eval ssh-agent and add keyfile:
root@:~# eval ssh-agent -s
Agent pid 4063
root@:~# ssh-add -l
The agent has no identities.
root@:~# ssh-add /root/.ssh/key
Enter passphrase for /root/.ssh/key:
Identity added: /root/.ssh/key (/root/.ssh/key)
root@:~# ssh-add -l
4096 SHA256:FxPiCFYOiRree0ogNPpo81DTDUqmr1Brlo0LFnFK12o /root/.ssh/key (RSA)
Why it work when I try to run it manually? How to fix that?
I want to add that to rc.local to autostart it when PC starts.
UPD
if I try to run only **script2** manually, it works (key adds to agent).
So I thing problem is with eval sh-agent, but I don't know what's wrong
Asked by rGA145
(449 rep)
Aug 21, 2016, 09:23 PM
Last activity: Aug 10, 2021, 11:15 PM
Last activity: Aug 10, 2021, 11:15 PM