Partage
  • Partager sur Facebook
  • Partager sur Twitter

probleme de connexion ssh tunnel

    17 janvier 2024 à 16:15:33

    Bonjour a tous, je souhaite creer un tunnel ssh pour me connecter sur un serveur distant. Le but est de creer une "passerelle" entre moi et un serveur.

    La gateway doit etre installé sur la machine en local donc on doit pouvoir se connecter avec cette commande "ssh orion@127.0.0.1 -p 36" puis on doit pouvoir taper des commandes qui passe par la gateway

    SSH connection established.

    Port forwarding from localhost:36 to *.*.*.*:22 is established.

    Command Result:

    /home/orion

    Visiblement la gateway se connecte correctement au serveur car la commande pwd affiche le bon résultat. Or impossible de se connecter sur la gateway.

    ssh orion@127.0.0.1 -p 36

    kex_exchange_identification: Connection closed by remote host

    Connection closed by 127.0.0.1 port 36

    Pour info j'ai désactivé mon pare feu

    using System;
    using Renci.SshNet;
    
    class Program
    {
        static void Main()
        {
            // Set SSH connection info
            string sshHost = "127.0.0.1";
            int sshPort = 36;
            string sshUsername = "orion";
            string sshPassword = "psw";
    
            string targetHost = "*.*.*.*";//ip du serveur
            int targetPort = 22;//port ssh du serveur
    
            using (var client = new SshClient(targetHost, targetPort, sshUsername, sshPassword))
            {
                try
                {
                    client.Connect();
                    Console.WriteLine("SSH connection established.");
    
                    // Set up port forwarding
                    var portForwarded = new ForwardedPortLocal("127.0.0.1", (uint)sshPort, targetHost, (uint)targetPort);
                    client.AddForwardedPort(portForwarded);
    
                    portForwarded.Start();
    
                    Console.WriteLine($"Port forwarding from localhost:{sshPort} to {targetHost}:{targetPort} is established.");
    
    
                    // Send the "pwd" command
                    using (var cmd = client.CreateCommand("pwd"))
                    {
                        var result = cmd.Execute();
                        Console.WriteLine($"Command Result:\n{result}");
                    }
    
                    // Keep the program running
                    Console.WriteLine("Press 'Q' to quit.");
                    while (Console.ReadKey().Key != ConsoleKey.Q)
                    {
                        // Keep the program running until 'Q' is pressed
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error: {ex.Message}");
                }
                finally
                {
                    client.Disconnect();
                    Console.WriteLine("SSH connection closed.");
                }
            }
        }
    }
    



    -
    Edité par JEANBAPTISTECOMTE1 18 janvier 2024 à 18:47:35

    • Partager sur Facebook
    • Partager sur Twitter
      23 janvier 2024 à 16:09:33

      Est-ce que la connexion ssh est autorisé sur le gateway ?
      • Partager sur Facebook
      • Partager sur Twitter
        24 janvier 2024 à 10:46:47

        Normalement oui, la gateway est sur mon PC et le pare feu est désactivé
        • Partager sur Facebook
        • Partager sur Twitter

        probleme de connexion ssh tunnel

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        • Editeur
        • Markdown