Here is what I am trying to achieve:
- SSH into an EC2 instance
Node1
.Public IP
is available for Node1.- I am using a
.pem
file to createConnection
with Node1.
- 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 ?