The below command works fine from my localhost and I get the desired output. See below
$ ssh -o ConnectTimeout=7 -o BatchMode=yes [email protected] "echo WORKS;exit"
Output:
WORKS
Now, I put this command in a script file test.sh
having sufficient execution privileges
$ cat test.sh
segment=$(ssh -o ConnectTimeout=7 -o BatchMode=yes [email protected] "echo WORKS;exit")
echo "SEGMENT $segment"
I don't get the desired output. Infact I get the below error:
$ ./test.sh
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
SEGMENT
I was expecting
SEGMENT WORKS
Now, the Permission denied error goes away but
Can you please suggest what could be the issue ?
ssh -i /<path_to_private_key>
was set is what it was working on local command line but in the script I had to specify the private key explicitly.bash
scripts. See e.g. unix.stackexchange.com/questions/368246/…