IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Connexion SSH à un serveur VPS à l'aide de Renci.SshNet


Sujet :

VB.NET

  1. #1
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2018
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2018
    Messages : 16
    Points : 17
    Points
    17
    Par défaut Connexion SSH à un serveur VPS à l'aide de Renci.SshNet
    Bonjour,
    Je voudrai établir une connexion SSH à un serveur VPS (1ère étape pour une connexion à un DB MySQL) à l'aide de Renci.SshNet.
    Je crois que le serveur est correctement paramétré car j'ai pu établir la connexion avec l'invite de commandes après avoir activé l'application Windows client OpenSSH.
    .Nom : connexion serveur LWS ssh avec cmd.png
Affichages : 382
Taille : 45,4 Ko

    Voici le code utilisé pour la connexion en VB.NET et qui retourne "Permission denied (password)":
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
    Try
                Dim myServerAddress As String = "vps6xxxx.lws-hosting.com"
                Dim myPassword As String = "XBXXXXXXXZD"
                Dim myUsername As String = "root@vps6xxxx.lws-hosting.com"
     
                Dim ci As ConnectionInfo =
                 New ConnectionInfo(myServerAddress, myUsername, New PasswordAuthenticationMethod(myUsername, myPassword))
     
                Dim testCon As String = "no"
                Using client As SshClient = New SshClient(ci)
     
                    client.Connect()
     
                    If client.IsConnected = True Then
                        testCon = "ok"
     
                        client.Disconnect()
     
                    End If
                End Using
                MsgBox(testCon)
     
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    Si vous avez des pistes pour réussir à établir la connexion en VB.NET...

  2. #2
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2018
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2018
    Messages : 16
    Points : 17
    Points
    17
    Par défaut
    A force d'essayer j'ai trouvé ce qui ne convenait pas: le Username ne doit pas être "root@vps6xxxx.lws-hosting.com" mais simplement "root"
    Le code corrigé complet:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
     
    Public Function TestConnexionSql() As Boolean
            Dim test As Boolean = False
            Try
                Dim myServerAddress As String = "185.XX.XXX.XXX"
                Dim usernameSsh As String = "root"
                Dim passwordSsh As String = "XXXXXXXD"
                Dim portSsh As Integer = 22
                Dim myDataBase As String = "c0DB"
                Dim usernameSql As String = "c0moi"
                Dim passwordSql As String = "wxxxxxx4"
                Dim portSql As Integer = 3306
     
                Dim pam As PasswordAuthenticationMethod = New PasswordAuthenticationMethod(usernameSsh, passwordSsh)
     
                Dim ci As ConnectionInfo =
                 New ConnectionInfo(myServerAddress, portSsh, usernameSsh, pam)
                With ci
                    .Timeout = TimeSpan.FromSeconds(30)
                End With
     
                Using client As SshClient = New SshClient(ci)
     
                    AddHandler client.HostKeyReceived, AddressOf CanTrustTrue
     
                    client.Connect()
     
                    If client.IsConnected = True Then
     
                        Using portFwld As ForwardedPortLocal = New ForwardedPortLocal("127.0.0.1", CType(portSql, UInteger), "127.0.0.1", CType(portSql, UInteger))
     
                            client.AddForwardedPort(portFwld)
                            portFwld.Start()
                            If portFwld.IsStarted Then
                                Dim ConnectionString As String = "SERVER=" & "127.0.0.1" &
                                 ";PORT=" & CStr(portSql) &
                                 ";DATABASE=" & myDataBase &
                                 ";UID=" & usernameSql &
                                 ";PASSWORD=" & passwordSql & ";"
                                Using conn As MySqlConnection = New MySqlConnection(ConnectionString)
                                    conn.Open()
     
                                    test = True
     
                                End Using
                                portFwld.Stop()
                            Else
                                test = False
                            End If
                        End Using
                        client.Disconnect()
                    Else
                        test = False
                    End If
                End Using
     
                Return test
     
            Catch ex As Exception
                MsgBox(ex.Message & Chr(10) & ex.StackTrace)
                Return False
            End Try
        End Function

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Connexion SSH multiple serveurs
    Par musha76 dans le forum Linux
    Réponses: 2
    Dernier message: 08/09/2017, 18h21
  2. connexion ssh ubuntu serveur
    Par nezar1990 dans le forum Sécurité
    Réponses: 2
    Dernier message: 17/04/2011, 19h24
  3. connexion impossible en ssh vers serveur dedié
    Par tifsa dans le forum Administration système
    Réponses: 4
    Dernier message: 10/11/2008, 13h04
  4. [debutant] connexion ssh pour redémarrer un serveur
    Par san1981 dans le forum Réseau
    Réponses: 6
    Dernier message: 12/09/2008, 18h17
  5. [Système] Connexion ssh à un serveur distant
    Par Bomba dans le forum Langage
    Réponses: 1
    Dernier message: 04/05/2007, 06h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo