Unable to SSH to localhost:22

From my application tests I’m trying to run some simple commands via SSH. I thought that I’d be able to do it via localhost on the hosted GitHub runner but I’m getting “Connection Refused”.

Here are the full credientials that I’m using:

  • hostname: 127.0.0.1
  • port:22
  • username: root
  • password: ‘’ (empty)

I’ve even tried to setup another image of “ubuntu:latest” and mapped the port to something unique and tried again, but I’m still not getting through.

Any ideas?

That sounds like there is no SSH service running. I haven’t checked what the runner VMs do by default, but the “ubuntu:latest” Docker container definitely isn’t going to have one without modifications. You can try installing the openssh-server package. On the runner host that should automatically start the service, in a container you’ll have to do that manually.

I did try to install the openssh-server package on the host and it was already installed and activly listening to port 22.

I’m wondering if I have the credentials for the host wrong?

Possibly, last time I checked the documentation for runners only said that passwordless sudo is enabled, not that the root password is empty. You could always try setting up pubkey login.

However, “Connection Refused” generally means there is either nothing listening on the target IP/port combination, or a firewall rejected the connection. Authentication failure should give you a different error message. Are you possibly running the ssh command in a container?

I checked the status of openssh-server and it was indeed active and listening on port 22. (This is all on the runner) The tests are being executed directly on the runner too. I only added the additional image to try and replicate an external server.

I had this issue, To make it go I had to create a key, create the authorized_keys file, set the permissions, and then ensure that the permissions on the users home folder are set to 0755. Once I did all this ssh to localhost worked a treat.

Here are the actual actions I ended up with -

I hope this helps someone else, who’s attempting to do something similar.

1 Like