Reputation: 11
I need to make an application that runs in Raspberrypi where I can transfer files using ssh from the host Windows machine to the remote pi. and also execute a few read-a-file commands there. Hence I have to use these lines "#include <libssh/libssh.h>" the issue while I am trying to authenticate the sshsession using privatekey ,I am unable to do. Please find the respective function below:
ool SSHManager::connectWithPrivateKey(const QString &host, const QString &username, const QString &privateKeyPath) {
if (!sshSession) {
return false;
}
int verbosity = SSH_LOG_PROTOCOL;
ssh_options_set(sshSession, SSH_OPTIONS_HOST, host.toUtf8().constData());
ssh_options_set(sshSession, SSH_OPTIONS_USER, username.toUtf8().constData());
ssh_options_set(sshSession, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
if (ssh_connect(sshSession) != SSH_OK) {
qDebug() << "Failed to connect to the SSH server";
return false;
}
if (ssh_userauth_publickey_auto(sshSession, nullptr, nullptr) != SSH_AUTH_SUCCESS) {
qDebug() << "SSH public key authentication failed";
if (ssh_userauth_privatekey_file(sshSession, nullptr, privateKeyPath.toUtf8().constData(), nullptr) != SSH_AUTH_SUCCESS) {
qDebug() << "SSH authentication with private key file failed";
return false;
}
}
return true;
}
I am unable to authenticate via password but not using my private key. the error what Iam getting in my QT is as below:
2023/09/08 20:39:29.411090, 2] ssh_client_connection_callback: SSH server banner: SSH-2.0-OpenSSH_7.4p1 Raspbian-10+deb9u7
[2023/09/08 20:39:29.411586, 2] ssh_analyze_banner: Analyzing banner: SSH-2.0-OpenSSH_7.4p1 Raspbian-10+deb9u7
[2023/09/08 20:39:29.411586, 2] ssh_analyze_banner: We are talking to an OpenSSH server version: 7.4 (70400)
[2023/09/08 20:39:29.413103, 1] ssh_known_hosts_read_entries: Failed to open the known_hosts file '/etc/ssh/ssh_known_hosts': No such file or directory
[2023/09/08 20:39:29.415063, 2] ssh_kex_select_methods: Negotiated curve25519-sha256,ssh-ed25519,[email protected],[email protected],aead-poly1305,aead-poly1305,none,none,,
[2023/09/08 20:39:29.574564, 2] ssh_init_rekey_state: Set rekey after 134217728 blocks
[2023/09/08 20:39:29.574564, 2] ssh_init_rekey_state: Set rekey after 134217728 blocks
[2023/09/08 20:39:29.574564, 2] ssh_packet_client_curve25519_reply: SSH_MSG_NEWKEYS sent
[2023/09/08 20:39:29.574564, 2] ssh_packet_newkeys: Received SSH_MSG_NEWKEYS
[2023/09/08 20:39:29.577011, 2] ssh_packet_newkeys: Signature verified and valid
[2023/09/08 20:39:29.577968, 1] ssh_pki_import_pubkey_file: Error opening C:\Users\****/.ssh/id_ed25519.pub: No such file or directory
[2023/09/08 20:39:29.578465, 1] ssh_pki_import_privkey_file: Error opening C:\Users\****/.ssh/id_ed25519: No such file or directory
[2023/09/08 20:39:29.579460, 1] ssh_pki_import_pubkey_file: Error opening C:\Users\****/.ssh/id_ecdsa.pub: No such file or directory
[2023/09/08 20:39:29.579955, 1] ssh_pki_import_privkey_file: Error opening C:\Users\***/.ssh/id_ecdsa: No such file or directory
SSH public key authentication failed
[2023/09/08 20:39:29.581333, 1] ssh_userauth_try_publickey: The key algorithm 'ssh-rsa' is not allowed to be used by PUBLICKEY_ACCEPTED_TYPES configuration option
[2023/09/08 20:39:29.581333, 2] ssh_userauth_publickey_auto: Tried every public key, none matched
[2023/09/08 20:39:29.581942, 1] ssh_pki_import_pubkey_file: Error opening new_key.pub: No such file or directory
[2023/09/08 20:39:29.581942, 1] ssh_userauth_privatekey_file: Public key file new_key.pub not found. Trying to generate it.
[2023/09/08 20:39:29.582439, 2] ssh_pki_import_privkey_base64: Trying to decode privkey passphrase=false
[2023/09/08 20:39:29.585288, 1] ssh_userauth_publickey: The key algorithm 'ssh-rsa' is not allowed to be used by PUBLICKEY_ACCEPTED_TYPES configuration option
SSH authentication with private key file failed
Kindly note that I am using private key in Openssh format. Please help me to find a solution to authenticate the remote raspberry pi using privatekey libssh method.
Upvotes: 0
Views: 17