In my Bash script, I use SCP to copy some files to another machine.
But I'm using Keychain program on all my hosts. When the ssh-agent is already loaded by Keychain, there is no problem.
But, when the key of the remote host isn't already loaded, after the connection, Keychain displays a message to add the key, but never ask the passphrase... The file is not copied... and the connection isn't closed.
* keychain 2.7.1 ~ http://www.funtoo.org
* Waiting 5 seconds for lock...
* Found existing ssh-agent: 31914
* Adding 1 ssh key(s): /root/.ssh/id_rsa
With SSH, the passphrase prompt is correctly displayed, if the key is not loaded :
* keychain 2.7.1 ~ http://www.funtoo.org
* Found existing ssh-agent: 27551
* Adding 1 ssh key(s): /root/.ssh/id_rsa
Enter passphrase for /root/.ssh/id_rsa:
Is there a way/workaround to detect if the file has been copied ?
In fact, the root cause is the distant .bashrc I think ... Keychain is launched when the .bashrc is sourced.
Edit : Keychain has a --noask
option. So SCP command works with this option, because passphrase isn't asked, but I really need to be asked about the key with SSH.
On Destination server, is it possible to detect if ssh OR scp command is launched ?
Assuming you have control of the .bashrc file on the remote system, why not just change the way keychain is started based on whether the session is a tty
or not? This way you could start it with the --noask
option as you described when scp (no tty) is being used, and without that option for ssh.
if [ -t 1 ] then
<start keychain normally>
else
<start keychain with --noask>
fi