1

Here is what I am trying to achieve:

  1. SSH into an EC2 instance Node1.
    • Public IP is available for Node1.
    • I am using a .pem file to create Connection with Node1.
  2. From Node1 ssh into localhost on port 2022: ssh admin@localhost -p 2022
    • Now execute a command, while inside localhost.

Here is the code snippet I am using:

from fabric2 import Connection

jump_host_ip = "A.B.C.D"
user = "root_user"
pem_key = "example.pem"

with Connection(jump_host_ip, user=user, connect_kwargs={"key_filename": pem_key}) as jump_host:
    with Connection('localhost', user='dummy_user', port=2022,
                    connect_kwargs={'password': 'password'}, gateway=jump_host) as local_host:
        local_host.run('ls -la')

This code is hosted on another EC2 server. And when executed from the EC2 server it throws the following exception:

paramiko.ssh_exception.AuthenticationException: Authentication failed.

But this code works when executed from a local machine (not from EC2 server).

Is it possible EC2 could be blocking the Connection to localhost through gateway ? If yes, what should be the fix for this ?

kusamit
  • 19
  • 3
  • @MartinPrikry: When I try this manually from terminal, the ssh is successful. And there is no authentication failure. 1. I do ssh into Node1: ssh user@node1 2. From Node1 I execute: ssh admin@localhost -p 2022. It asks me for the password. And it works. In which possible scenario the target server could block the authentication ? Could it be related to the port number (i.e. 2022) ? – kusamit Jun 15 '21 at 19:10
  • Adding `'look_for_keys': False` to `connect_kwargs` fixed this issue for me. Thanks @MartinPrikryl for your inputs. – kusamit Jul 08 '21 at 14:30

0 Answers0