# \[SOLVED\] Port 22 refuses connection + ssh new port not working anymore

**URL:** https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855
**Category:** Support
**Tags:** fail2ban, ssh, yunohost-firewall, english
**Created:** [December 31, 2022, 3:22am UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855 "2022-12-31T03:22:46Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![unmy](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/u/dfb087/32.png) [@unmy](https://forum.yunohost.org/u/unmy)
#### Post date: [December 31, 2022, 3:22am UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/1 "2022-12-31T03:22:46Z")

</div>

**Hardware:** VPS bought online ( Contabo )  
**YunoHost version:** 11.1.0.2 (stable)  
**I have access to my server :** Through SSH and browser  
**Are you in a special context or did you perform some particular tweaking on your YunoHost instance ?** : no

hi!  
im trying to sync a directory from my machine to my yunohost servers but, with either `scp` or `rsync` i always get the same error:

`ssh: connect to host mms.nohost.me port 22: Connection refused`

the port is present and open in the firewall section.

anyone can help? 🤗

---

<div class="post-metadata">

### Author: ![Aleks](https://forum.yunohost.org/user_avatar/forum.yunohost.org/aleks/32/1704_2.png) [@Aleks](https://forum.yunohost.org/u/Aleks)
#### Post date: [December 31, 2022, 3:55am UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/2 "2022-12-31T03:55:32Z")

</div>

sounds like you tried multiple time to connect with incorrect crendentials and got (temporarily) banned by fail2ban …

(Though could be something else too)

---

<div class="post-metadata">

### Author: ![unmy](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/u/dfb087/32.png) [@unmy](https://forum.yunohost.org/u/unmy)
#### Post date: [December 31, 2022, 10:20am UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/3 "2022-12-31T10:20:32Z")

</div>

it happened since the first attempt, but probably this fail2ban issue is related to [this](https://forum.yunohost.org/t/postfix-smtp-server/22854)? i received around 10 more similar emails overnight.

---

<div class="post-metadata">

### Author: ![unmy](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/u/dfb087/32.png) [@unmy](https://forum.yunohost.org/u/unmy)
#### Post date: [January 1, 2023, 2:10pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/4 "2023-01-01T14:10:31Z")

</div>

or may be because of this:

> =================================
> 
> Base system (basesystem)
> 
> =================================
> 
> [WARNING] There’s been a suspiciously high number of authentication failures recently. You may want to make sure that fail2ban is running and is correctly configured, or use a custom port for SSH as explained in [Security | Yunohost Documentation](https://yunohost.org/security).

i checked already and fail2ban is working.

---

<div class="post-metadata">

### Author: ![jarod5001](https://forum.yunohost.org/user_avatar/forum.yunohost.org/jarod5001/32/5323_2.png) [@jarod5001](https://forum.yunohost.org/u/jarod5001)
#### Post date: [January 1, 2023, 3:47pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/5 "2023-01-01T15:47:57Z")

</div>

Change the port

---

<div class="post-metadata">

### Author: ![unmy](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/u/dfb087/32.png) [@unmy](https://forum.yunohost.org/u/unmy)
#### Post date: [January 1, 2023, 3:49pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/6 "2023-01-01T15:49:34Z")

</div>

are we talking about the ssh port?  
i’ve done that a long time ago.  
should i do it again?

---

<div class="post-metadata">

### Author: ![unmy](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/u/dfb087/32.png) [@unmy](https://forum.yunohost.org/u/unmy)
#### Post date: [January 1, 2023, 6:12pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/7 "2023-01-01T18:12:45Z")

</div>

i did it anyway, but a couple of warnings came up:

```auto
Info: Saving the new configuration...
Success! Configuration updated for 'ssh'
Success! Configuration updated for 'fail2ban'
Warning: Job for ssh.service failed because the control process exited with error code.
Warning: See "systemctl status ssh.service" and "journalctl -xe" for details.
Error: Could not run script: /usr/share/yunohost/hooks/conf_regen/03-ssh
Warning: Some firewall rule commands have failed. More info in log.
Success! Config updated as expected

```

[this](https://paste.yunohost.org/raw/dekirutike) it the log.

and eventually the port hasn’t been changed and the “new old” one doesn’t seem to work anymore. 🙃

---

<div class="post-metadata">

### Author: ![Aleks](https://forum.yunohost.org/user_avatar/forum.yunohost.org/aleks/32/1704_2.png) [@Aleks](https://forum.yunohost.org/u/Aleks)
#### Post date: [January 1, 2023, 10:04pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/8 "2023-01-01T22:04:54Z")

</div>

Then what does `journalctl -u sshd -n 100 --no-pager --no-hostname` tells

---

<div class="post-metadata">

### Author: ![unmy](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/u/dfb087/32.png) [@unmy](https://forum.yunohost.org/u/unmy)
#### Post date: [January 1, 2023, 10:07pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/9 "2023-01-01T22:07:03Z")

</div>

where should i input it?  
because if i run it now in my terminal i get no entries.

---

<div class="post-metadata">

### Author: ![Aleks](https://forum.yunohost.org/user_avatar/forum.yunohost.org/aleks/32/1704_2.png) [@Aleks](https://forum.yunohost.org/u/Aleks)
#### Post date: [January 1, 2023, 10:09pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/10 "2023-01-01T22:09:17Z")

</div>

Zblerg then lets try `systemctl status ssh.service | cat`

---

<div class="post-metadata">

### Author: ![Aleks](https://forum.yunohost.org/user_avatar/forum.yunohost.org/aleks/32/1704_2.png) [@Aleks](https://forum.yunohost.org/u/Aleks)
#### Post date: [January 1, 2023, 10:09pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/11 "2023-01-01T22:09:48Z")

</div>

or also maybe `sshd -t`

---

<div class="post-metadata">

### Author: ![unmy](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/u/dfb087/32.png) [@unmy](https://forum.yunohost.org/u/unmy)
#### Post date: [January 1, 2023, 10:13pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/12 "2023-01-01T22:13:32Z")

</div>

> [@Aleks](#):
>
> Zblerg then lets try `systemctl status ssh.service | cat`

```auto
xoxo:~$ systemctl status ssh.service | cat
Unit ssh.service could not be found.

```

> [@Aleks](#):
>
> or also maybe `sshd -t`

```auto
:~$ sshd -t
sshd: no hostkeys available -- exiting.

```

none of them seem promising…

---

<div class="post-metadata">

### Author: ![Aleks](https://forum.yunohost.org/user_avatar/forum.yunohost.org/aleks/32/1704_2.png) [@Aleks](https://forum.yunohost.org/u/Aleks)
#### Post date: [January 1, 2023, 10:14pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/13 "2023-01-01T22:14:57Z")

</div>

Hmmm can you confirm that you’re running those on your server and not your own machine …

---

<div class="post-metadata">

### Author: ![jarod5001](https://forum.yunohost.org/user_avatar/forum.yunohost.org/jarod5001/32/5323_2.png) [@jarod5001](https://forum.yunohost.org/u/jarod5001)
#### Post date: [January 1, 2023, 10:16pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/14 "2023-01-01T22:16:21Z")

</div>

In the log, I saw you used a port outside the range permitted.

> Port numbers range from **0 to 65536**

---

<div class="post-metadata">

### Author: ![Aleks](https://forum.yunohost.org/user_avatar/forum.yunohost.org/aleks/32/1704_2.png) [@Aleks](https://forum.yunohost.org/u/Aleks)
#### Post date: [January 1, 2023, 10:17pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/15 "2023-01-01T22:17:11Z")

</div>

Hmyeah indeed

---

<div class="post-metadata">

### Author: ![unmy](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/u/dfb087/32.png) [@unmy](https://forum.yunohost.org/u/unmy)
#### Post date: [January 1, 2023, 10:19pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/16 "2023-01-01T22:19:33Z")

</div>

> [@Aleks](#):
>
> Hmmm can you confirm that you’re running those on your server and not your own machine …

> [@unmy](#):
>
> and eventually the port hasn’t been changed and the “new old” one doesn’t seem to work anymore.

not on my server because i can’t enter it through ssh anymore…

> [@jarod5001](#):
>
> Port numbers range from **0 to 65536**

guess that might have caused the error, but now neither of the two works.

---

<div class="post-metadata">

### Author: ![unmy](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/u/dfb087/32.png) [@unmy](https://forum.yunohost.org/u/unmy)
#### Post date: [January 1, 2023, 10:25pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/17 "2023-01-01T22:25:23Z")

</div>

by accessing Tools through the web browsser portal i can get [the logs](https://paste.yunohost.org/megahexuqu) of `ssh`, which status is _failed_ btw.

---

<div class="post-metadata">

### Author: ![jarod5001](https://forum.yunohost.org/user_avatar/forum.yunohost.org/jarod5001/32/5323_2.png) [@jarod5001](https://forum.yunohost.org/u/jarod5001)
#### Post date: [January 1, 2023, 10:29pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/18 "2023-01-01T22:29:56Z")

</div>

Now you 're locked out of your server. I don’t know if you have an emergency access on your vps, that would be helpful to restore the port to 22, restart sshd. Or you can try a terminal app on yunohost.  
After you get a working 22 port, change it using [Security | Yunohost Documentation](https://yunohost.org/en/security?q=%2Fsecurity#modify-the-ssh-port)  
Test it and close port 22

---

<div class="post-metadata">

### Author: ![jarod5001](https://forum.yunohost.org/user_avatar/forum.yunohost.org/jarod5001/32/5323_2.png) [@jarod5001](https://forum.yunohost.org/u/jarod5001)
#### Post date: [January 1, 2023, 10:45pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/19 "2023-01-01T22:45:57Z")

</div>

Seems we have a bug here. security.ssh.port must not be in the wrong range

> sshd[1268424]: /etc/ssh/sshd\_config line 7: Badly formatted port number

.

---

<div class="post-metadata">

### Author: ![unmy](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/u/dfb087/32.png) [@unmy](https://forum.yunohost.org/u/unmy)
#### Post date: [January 1, 2023, 10:49pm UTC](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855/20 "2023-01-01T22:49:21Z")

</div>

> [@jarod5001](#):
>
> emergency access on your vps

i do, it gave me root access through ssh but now im not sure how should i restore the port.  
i found this online:

```auto
rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server

```

is that correct?

[Next page](https://forum.yunohost.org/t/solved-port-22-refuses-connection-ssh-new-port-not-working-anymore/22855.md?page=2)
