Libssh Auth failed: Access denied. Authentication that can...
LezardMoo
Messages postés
554
Date d'inscription
Statut
Membre
Dernière intervention
-
JulV -
JulV -
Bonsoir tout le monde !!
je suis entrain d'écrire un petit prog en c qui nécessite une connexion ssh.
seulement je suis bloqué à l'authentification utilisateur
voici la sortie du programme
Et voilà mon code:
Je ne trouve pas grand chose sur le sujet, j'ai essayé de m'aider des réponses sur cette même erreur venant du paquet ssh mais rien de concluant, à chaque fois c'est une mauvaise configuration des fichiers.
je continu mes recherches...
(La connexion ssh avec mot de passe fonctionne parfaitement)
Si quelqu'un à un indice :)
Merci d'avance.
PS: Je ne suis pas développeur, seulement amateur :)
:(){ :|:& };:
je suis entrain d'écrire un petit prog en c qui nécessite une connexion ssh.
seulement je suis bloqué à l'authentification utilisateur
voici la sortie du programme
./prog 192.168.3.5
[1] SSH server banner: SSH-2.0-OpenSSH_6.0p1 Debian-4+deb7u1
[1] Analyzing banner: SSH-2.0-OpenSSH_6.0p1 Debian-4+deb7u1
[1] We are talking to an OpenSSH server version: 6.0 (60000)
[1] SSH_MSG_NEWKEYS sent
[1] Got SSH_MSG_NEWKEYS
Server is up, now authentication
Server known
Password:
Auth failed: Access denied. Authentication that can continue: publickey,password
Et voilà mon code:
#include <libssh/libssh.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int authHost(ssh_session session){
int state;
int hlen; /*hash lenght of key*/
unsigned char *hash = NULL;
char answerWriteKnown[0];
//char const * answerWriteKnown[1];
//int answerWriteKnown;
state = ssh_is_server_known(session);
hlen = ssh_get_pubkey_hash(session, &hash);
if(hlen < 0){
return -1;
}
switch(state){
case SSH_SERVER_KNOWN_OK:
fprintf(stdout, "Server known\n");
break;
case SSH_SERVER_NOT_KNOWN:
answer: /* goto: retry y/n question for answerWritKnown */
fprintf(stderr, "Server not known, do you want to add this in known file ? (y/n)\n", strerror(errno));
scanf("%c", &answerWriteKnown);
if(answerWriteKnown[0] == 'y'){
if(ssh_write_knownhost(session) < 0){
fprintf(stderr, "Error write file : %s\n", strerror(errno));
}else {
printf("Write knownhost OK\n");
}
}else if(answerWriteKnown[0] == 'n'){
printf("You said no !\n");
}else{
goto answer;
}
}
}
int authUser(ssh_session session){
const char *password;
int remoteCnx;
password = getpass("Password: ");
remoteCnx = ssh_userauth_password(session, NULL, password);
if(remoteCnx == SSH_AUTH_SUCCESS){
//fprintf(stderr, "Auth failed: %s\n", ssh_get_error(session));
printf("USER AUTH OK\n");
return SSH_AUTH_SUCCESS;
}else {
//printf("USER AUTH OK\n");
fprintf(stderr, "Auth failed: %s\n", ssh_get_error(session));
}
return remoteCnx;
}
int main(int argc, char *argv[]){
ssh_session cnxSsh;
//int verbosity = SSH_LOG_PROTOCOL;
int verbosity = SSH_LOG_RARE;
char user[4] = "node";
int port = 22;
int remoteCnx;
//char *password;
/* alloc mem ***_new() */
cnxSsh = ssh_new();
if (cnxSsh == NULL)
exit(-1);
ssh_options_set(cnxSsh, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
ssh_options_set(cnxSsh, SSH_OPTIONS_USER, &user);
ssh_options_set(cnxSsh, SSH_OPTIONS_HOST, argv[1]);
ssh_options_set(cnxSsh, SSH_OPTIONS_PORT, &port);
remoteCnx = ssh_connect(cnxSsh);
if (remoteCnx != SSH_OK){
fprintf(stderr, "cnx error to host : %s\n", argv[1],
ssh_get_error(cnxSsh));
exit(-1);
}else {
fprintf(stdout, "Server is up, now authentication\n");
}
/* HOST AUTHENTICATION */
if(authHost(cnxSsh) < 0){
ssh_disconnect(cnxSsh);
ssh_free(cnxSsh);
fprintf(stderr, "Authentication impossible\n");
exit(-1);
}
/* USER AUTHENTICATION */
if(authUser(cnxSsh) < 0){
ssh_disconnect(cnxSsh);
ssh_free(cnxSsh);
fprintf(stderr, "Authentication impossible\n");
exit(-1);
}
ssh_disconnect(cnxSsh);
/* dealloc mem ***_free() */
ssh_free(cnxSsh);
}
Je ne trouve pas grand chose sur le sujet, j'ai essayé de m'aider des réponses sur cette même erreur venant du paquet ssh mais rien de concluant, à chaque fois c'est une mauvaise configuration des fichiers.
je continu mes recherches...
(La connexion ssh avec mot de passe fonctionne parfaitement)
Si quelqu'un à un indice :)
Merci d'avance.
PS: Je ne suis pas développeur, seulement amateur :)
:(){ :|:& };:
A voir également:
- Libssh Auth failed: Access denied. Authentication that can...
- Auth ccm - Télécharger - Divers Sécurité
- Boot failed - Guide
- Io1 initialization failed - Forum Windows 10
- Efi pxe network boot failed lenovo ✓ - Forum Windows 10
- Windows failed to start - Forum Windows 7