# Port 22 Connection Refused to the server

**URL:** <https://forum.ansible.com/t/port-22-connection-refused-to-the-server/35815>\
**Category:** AWX Project\
**Tags:** ubuntu\
**Created:** [October 4, 2021, 6:07am UTC](https://forum.ansible.com/t/port-22-connection-refused-to-the-server/35815 "2021-10-04T06:07:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![potta\_vamsi\_krishna](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@potta\_vamsi\_krishna](https://forum.ansible.com/u/potta_vamsi_krishna)\
**Post date:** [October 4, 2021, 6:07am UTC](https://forum.ansible.com/t/port-22-connection-refused-to-the-server/35815/1 "2021-10-04T06:07:27Z")

</div>

When I am creating an ec2 instance using ansible and trying to make an ssh connection in between those two servers, I am getting an issue like this:

TASK [SSH connection between the ansible server and the new server] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [localhost]: FAILED! =\> {“changed”: true, “cmd”: “cat ~/.ssh/id\_rsa.pub | ssh -vvv -p 22 -i ~/.ssh/my.key ubuntu@xx.xx.xxx.xx "cat \>\> ~/.ssh/authorized\_keys"”, “delta”: “0:00:03.052818”, “end”: “2021-10-04 05:57:48.631244”, “msg”: “non-zero return code”, “rc”: 255, “start”: “2021-10-04 05:57:45.578426”, “stderr”: “OpenSSH\_8.2p1 Ubuntu-4ubuntu0.3, OpenSSL 1.1.1f 31 Mar 2020\r\ndebug1: Reading configuration data /root/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh\_config\r\ndebug2: resolve\_canonicalize: hostname xx.xx.xxx.xx is address\r\ndebug2: ssh\_connect\_direct\r\ndebug1: Connecting to xx.xx.xxx.xx  
[xx.xx.xxx.xx] port 22.\r\ndebug1: connect to address xx.xx.xxx.xx port 22: Connection refused\r\nssh: connect to host xx.xx.xxx.xx port 22: Connection refused”, “stderr\_lines”: [“OpenSSH\_8.2p1 Ubuntu-4ubuntu0.3, OpenSSL 1.1.1f 31 Mar 2020”, “debug1: Reading configuration data /root/.ssh/config”, “debug1: Reading configuration data /etc/ssh/ssh\_config”, “debug2: resolve\_canonicalize: hostname xx.xx.xxx.xx is address”, “debug2: ssh\_connect\_direct”, “debug1: Connecting to xx.xx.xxx.xx  
[xx.xx.xxx.xx] port 22.”, “debug1: connect to address xx.xx.xxx.xx port 22: Connection refused”, “ssh: connect to host xx.xx.xxx.xx port 22: Connection refused”], “stdout”: “”, “stdout\_lines”: }

Here “xx.xx.xxx.xx” means my newly created server’s public ip.

Any help would appreciate.

Thanks in Advance
