Reputation: 1414
I was wondering about using SSH_ASKPASS to initiate an SSH session from a script, and so I wrote a script like this:
export SSH_ASKPASS="/path/passwordScript"
setsid ssh "username"@"host"
where passwordScript is a bash script that echoes the user's password like this:
#!/usr/bin/env bash
echo "the_password"
Where "the_password" is the user's password. This process worked fine, and the SSH session connected successfully.
Out of curiosity, I tried to change passwordScript to a c script like this (obviously this is the uncompiled version):
#include <stdio.h>
main()
{
printf("the_password\n");
}
To my surprise, the SSH session would no longer connect. The output looks like this:
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).
I thought perhaps the bash interpreter wasn't actually being used, and sh was being used by default or something. However, the SSH session works fine if I setup passwordScript in python like this:
#!/usr/bin/env python
print "the_password"
So my question is why doesn't ASK_PASS work with my c program?
(As an aside, I know that SSH keys are better suited for this situation; this was just a learning exercise)
Thanks!
Upvotes: 1
Views: 693
Reputation: 1414
My guess is that SSH_ASKPASS checks the return code. If I modify the c program to have return code 0 everything works as expected:
#include <stdio.h>
int main ()
{
printf("the_password");
return 0;
}
Upvotes: 2