Hi,

Why don't you just pass the identity key filename as an option, then use
ssh_userauth_autopubkey ?

I usually do
ssh_options_set (mySshSession, SSH_OPTIONS_USER, "username");
ssh_options_set (mySshSession, SSH_OPTIONS_IDENTITY, "/path/to/id_rsa");

and then call the following method do do the authentication:

int rv = ssh_userauth_autopubkey (mySshSession, NULL);

This is very simple and works nice :-)

Br,
David

On Fri, Mar 18, 2016 at 12:27 PM, Sruthi Mohan (RBEI/EIA1) <
sruthi.mo...@in.bosch.com> wrote:

> Dear All,
>
> I am trying to connect to the server using ssh.
> I get  Access denied for ssh_user_auth_none. Authentication that can
> continue Public key
> As per ssh_userauth_list list PUBLIC KEY authentication is valid
>
> Post that ssh_userauth_try_publickey and ssh_pki_import_pubkey_file also
> fails. Kindly let me know the possible reason failure
>
>
> Attached code below
>
> int main(int argc, char *argv[])
> {
>     QCoreApplication a(argc, argv);
>     ssh_session my_ssh_session;
>     int verbosity = SSH_LOG_PROTOCOL;
>     int port = 155;
>     my_ssh_session = ssh_new();
>     if (my_ssh_session == NULL)
>     {
>         exit(-1);
>     }
>     ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, myip);
>     ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY,
> &verbosity);
>     ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
>
>    int rc = ssh_connect(my_ssh_session);
>     if (rc != SSH_OK)
>     {
>     qDebug()<<"Error connecting to host:"<<ssh_get_error(my_ssh_session);
>       exit(-1);
>     }
>     rc=verify_knownhost(my_ssh_session);
>     rc = ssh_userauth_none(my_ssh_session, NULL);
>     if (rc != SSH_AUTH_SUCCESS) {
>        qDebug()<<"Error connecting to localhost: %s\n"
> <<ssh_get_error(my_ssh_session);
>        // return rc;
>     }
>     int method = ssh_userauth_list(my_ssh_session, NULL);
>
>     if (method & SSH_AUTH_METHOD_NONE)
>     {
>         qDebug()<<"Authenticate None";
>     }
>     if (method & SSH_AUTH_METHOD_PUBLICKEY)
>     {
>         qDebug()<<"Authenticate pubkey";
>     }
>     if (method & SSH_AUTH_METHOD_INTERACTIVE)
>     {
>         qDebug()<<"Authenticate keyboard";
>     }
>     if (method & SSH_AUTH_METHOD_PASSWORD)
>     {
>         qDebug()<<"Authenticate password";
>     }
>
> if (ssh_pki_import_pubkey_file(PublickeyFile.toStdString().c_str(),
> &pubkey) != SSH_OK)
>     {
>         qDebug()<<"Failed to import the key";
>     }
>     if(ssh_userauth_try_publickey(my_ssh_session,"S3DDM",pubkey)==
> SSH_ERROR)
>     {
>         qDebug()<<"Failed to import the key";
>     }
>
>
>     ssh_free(my_ssh_session);
>     ssh_disconnect(my_ssh_session);
>
>     return a.exec();
> }
>
>
> Best regards
>
> *Sruthi Mohan *
> *RBEI/EIA1*
>
> Tel. +91(80)6783-7826
>
>
>

Reply via email to