[Music]
hello i am
a cloud support engineer here at the aws
office in sydney today i am going to
show you how to resolve connection
refuse or connection timeout error when
trying to connect to an ec2 instance
with ssh
let's get started
to resolve connection refused or
connection timeout errors we need to
verify that there is in firewall
blocking the connection that sss service
daemon is running on the instance and
that ssh port 22 is in listening state
there are three methods of performing
these tasks
also be aware that method number two and
method number three requires instant
stop start and if your instance is
instant store backed or has instant
store volume containing data the data is
lost when the instance is stopped
also stopping and starting the instance
changes public ip address of your
instance it's best practice to use an
elastic ip address instead of public ip
address
method 1 use aws systems manager session
manager note that installation of ssm
agent is required to use this method and
instance should also meet systems
manager prerequisites
as you can see i am already logged into
the aws management console
i'll navigate to system manager console
on the systems manager home page in the
navigation pane choose session manager
choose start session
choose the instance and select start
session once the session is started
disable firewalls
and restart ssh service
the firewall command flashes all main
iptables rule not just for port 22.
verifying the ssh tcp port is in
listening state
choose terminate session
now try to connect to instance using ssh
method number 2
run the aws support troubleshoot ssh
automation document
from the systems manager home page in
the navigation pane choose automation
and select execute automation
in the search field enter aws support
troubleshoot ssh and select the
document in the execute automation
documents section choose simple
execution
in the input parameter section
specify the following parameters
for instance id specify the id of
unreachable instance for action select
fix all
for allow offline select true
allow the automation to complete
successfully and then ssh into the
instance method number three use a user
data script
from the aws ec2 management console
choose instances from navigation pane
and then select the instance you are
trying to connect to
choose instance state and stop the
instance
once the instant status is stopped
choose action
instance setting
edit user data
copy the following user data script into
edit user data dialog box
and then choose save
dimension script is also present in the
knowledge center article related to this
video
start the instance and check ssh
connectivity
finally note that preceding user data
script is set to run on every reboot of
the instance after regaining access to
your instance clear the user data script
section as added previously this
requires another stopping and starting
of the instance
thanks for watching and happy cloud
computing from all of us here at aws
[Music]
you