2
1
I am using libssh2
library to ssh connections in my mobile application. Here I want to use Agent Forwarding
support.
I have followed same procedure as they have provided in example here LibSSH2 Agent Forwarding.
I am able to create agent successfully but when I try to connect it with libssh2_agent_connect(agent)
It gives me error -39 LIBSSH2_ERROR_BAD_USE
.
Well I am checking same thing using MAC OSX terminal and it's working fine. Please suggest if anything wrong,
This is how I am trying once do successful connection
struct libssh2_agent_publickey *identity, *prev_identity = NULL;
int rc;
agent = libssh2_agent_init(session);
if (!agent)
{
fprintf(stderr, "Failure initializing ssh-agent support\n");
rc = 1;
}
int temp=libssh2_agent_connect(agent);
if (temp)
{
fprintf(stderr, "Failure connecting to ssh-agent\n");
rc = 1;
}
Is there anything wrong here? please suggest.
do you have any error or verbose output. "not working" is quite broad definition. – Jakuje – 2015-08-18T10:13:22.703
ohh sorry I missed that part, edited now in question also mentioning here. when I try to connect it with libssh2_agent_connect(agent) It gives me error -39 LIBSSH2_ERROR_BAD_USE. – Niks – 2015-08-18T10:16:30.457
just for sure. Do you have agent running? – Jakuje – 2015-08-18T10:18:49.750
Yes, It's running. I am able to ssh without ask/enter paraphrase when I try to ssh with my other machine where I have copied public key which I added to agent. – Niks – 2015-08-18T10:22:19.170
@Jakuje any idea? – Niks – 2015-08-19T12:44:09.890
I see agent is running. Where do you add the keys to the agent? – Jakuje – 2015-08-19T13:00:38.480
I have added keys from my mac terminal. I am trying from my iOS app with libssh2 library. With libssh2 i am unable to connect with agent – Niks – 2015-08-19T13:53:28.230
yes, I understand, but how you add the keys in iOS app? – Jakuje – 2015-08-19T14:21:57.047
while connecting to server I am using key like
const char *privatekey= [_privateKey cStringUsingEncoding:NSUTF8StringEncoding]; libssh2_userauth_publickey_fromfile(session, username, NULL,privatekey ,password);
once connection does successfully I am trying to connect agent with that session and same user. – Niks – 2015-08-20T06:02:43.640