# Changing SSH Port raises Error - Firewall is not updated

**URL:** <https://forum.yunohost.org/t/changing-ssh-port-raises-error-firewall-is-not-updated/40399>\
**Category:** Support\
**Tags:** ssh, yunohost-firewall, deutsch, english\
**Created:** [October 13, 2025, 8:08pm UTC](https://forum.yunohost.org/t/changing-ssh-port-raises-error-firewall-is-not-updated/40399 "2025-10-13T20:08:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![tinder](https://forum.yunohost.org/user_avatar/forum.yunohost.org/tinder/32/11441_2.png) [@tinder](https://forum.yunohost.org/u/tinder)\
**Post date:** [October 13, 2025, 8:08pm UTC](https://forum.yunohost.org/t/changing-ssh-port-raises-error-firewall-is-not-updated/40399/1 "2025-10-13T20:08:18Z")

</div>

**What type of hardware are you using** : VPS bought online  
**What YunoHost version are you running** : YunoHost 12.1.28 (stable)  
**How are you able to access your server** : The webadmin  
SSH

### Describe your issue

Hello,  
I would like to change the SSH port (22) of my YNH server. When I try to do this via the CLI, I get an error, and the same thing happens via the WebGUI. Only the entry ‘22’ seems to be allowed.

CLI command:  
`sudo yunohost settings set security.ssh.ssh_port -v xxxx`

Generates a KeyError.

The same thing happens in the WebGUI.

I can solve the problem by manually opening the new port in the firewall BEFOREHAND. Okay, that makes sense, of course. It seems that the firewall is not updated automatically. Is that intentional or just an oversight?

Many thanks

### Share relevant logs or error messages

CLI:  
[https://paste.yunohost.org/raw/duxuyeruwa](https://paste.yunohost.org/raw/duxuyeruwa)

WebGUI:  
no log available.  
Here are the lines from Install-Window:  
“Es ist ein interner Fehler in Yunohost aufgetreten”  
“Unerwarteter Serverfehler”

Saving the new configuration…  
Konfiguration aktualisiert für ‘ssh’  
Konfiguration aktualisiert für ‘fail2ban’  
Post-change hook for setting failed : 123  
Anwenden der neuen Konfiguration fehlgeschlagen: Ein unerwarteter Fehler ist aufgetreten  
Traceback (most recent call last):  
File “/usr/lib/python3/dist-packages/yunohost/utils/configpanel.py”, line 607, in set  
self.\_apply(self.form, self.config, previous\_settings)  
File “/usr/lib/python3/dist-packages/yunohost/settings.py”, line 264, in \_apply  
trigger\_post\_change\_hook(  
File “/usr/lib/python3/dist-packages/yunohost/settings.py”, line 291, in trigger\_post\_change\_hook  
f(setting\_name, old\_value, new\_value)  
File “/usr/lib/python3/dist-packages/yunohost/settings.py”, line 345, in reconfigure\_ssh\_and\_fail2ban  
firewall\_reload()  
File “/usr/lib/python3/dist-packages/yunohost/firewall.py”, line 566, in firewall\_reload  
if firewall.apply(upnp=not skip\_upnp):  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/usr/lib/python3/dist-packages/yunohost/firewall.py”, line 184, in apply  
if not self.config[“tcp”][ssh\_port][“open”]:

```auto
KeyError: 123
```

---

<div class="post-metadata">

**Author:** ![artlog](https://forum.yunohost.org/user_avatar/forum.yunohost.org/artlog/32/12399_2.png) [@artlog](https://forum.yunohost.org/u/artlog)\
**Post date:** [October 15, 2025, 11:36am UTC](https://forum.yunohost.org/t/changing-ssh-port-raises-error-firewall-is-not-updated/40399/2 "2025-10-15T11:36:13Z")

</div>

@tinder

there is ssh\_port variable so it should be possible to change it.  
Once reviewing code, your problem might be related to a recent change (14/09/2025, applies to 12.1.24 ) commit f6d08477c7ea47f3f57c787d66dd7c470dd8ba51  
that did add the line of code that generate the exception.

---

<div class="post-metadata">

**Author:** ![artlog](https://forum.yunohost.org/user_avatar/forum.yunohost.org/artlog/32/12399_2.png) [@artlog](https://forum.yunohost.org/u/artlog)\
**Post date:** [October 15, 2025, 11:51am UTC](https://forum.yunohost.org/t/changing-ssh-port-raises-error-firewall-is-not-updated/40399/3 "2025-10-15T11:51:15Z")

</div>

According to this old closed issue [Firewall not reloaded when regen-conf ssh after changing port · Issue #1946 · YunoHost/issues · GitHub](https://github.com/YunoHost/issues/issues/1946) it is fully valid to change ssh service default port.

---

<div class="post-metadata">

**Author:** ![artlog](https://forum.yunohost.org/user_avatar/forum.yunohost.org/artlog/32/12399_2.png) [@artlog](https://forum.yunohost.org/u/artlog)\
**Post date:** [October 15, 2025, 11:57am UTC](https://forum.yunohost.org/t/changing-ssh-port-raises-error-firewall-is-not-updated/40399/4 "2025-10-15T11:57:32Z")

</div>

@tinder This seems time for you to open an issue in [GitHub - YunoHost/issues: General issue tracker for the YunoHost project](https://github.com/YunoHost/issues) 😉

---

<div class="post-metadata">

**Author:** ![tinder](https://forum.yunohost.org/user_avatar/forum.yunohost.org/tinder/32/11441_2.png) [@tinder](https://forum.yunohost.org/u/tinder)\
**Post date:** [October 16, 2025, 8:28am UTC](https://forum.yunohost.org/t/changing-ssh-port-raises-error-firewall-is-not-updated/40399/5 "2025-10-16T08:28:40Z")

</div>

Someone beat me to it 🙂

> <https://github.com/YunoHost/issues/issues/2675>
>
> \### Describe the bug
> 
> An error occurs when trying to change the SSH port from th…e web admin
> 
> \### Context
> 
> \- Hardware: Odroid M1
> \- YunoHost version: 12.1.26
> \- I have access to my server: Through SSH, through the webadmin and direct access via keyboard / screen
> \- Are you in a special context or did you perform some particular tweaking on your YunoHost instance?: No
> \- Using, or trying to install package version/branch: N.A.
> \- If upgrading, current YunoHost version: N.A.
> 
> \### To reproduce
> 1. Go to \`yunohost/admin/#/tools/settings/security\`, 
> 2. Change the SSH port to a value that has never been used yet (meaning the port is not already opened in the firewall)
> 3. Click on save button
> 4. Observe error
> 
> Error when trying to change the ssh port to 2323 : 
> \`\`\`
> 2025-10-02 08:45:35,041 DEBUG yunohost.log.close - Journal complet de cette opération : '\<a href="#/tools/logs/20251002-084525-regen\_conf-2\_categories" style="text-decoration :underline"\> Régénérer les configurations du système '2\_categories' \</a\>'
> 2025-10-02 08:45:35,177 ERROR yunohost.settings.\_apply - Post-change hook for setting failed : 2323
> 2025-10-02 08:45:35,185 ERROR yunohost.configpanel.set - Échec de l'application de la nouvelle configuration : Une erreur inattendue est survenue : 
> Traceback (most recent call last):
> File "/usr/lib/python3/dist-packages/yunohost/utils/configpanel.py", line 607, in set
> self.\_apply(self.form, self.config, previous\_settings)
> File "/usr/lib/python3/dist-packages/yunohost/settings.py", line 264, in \_apply
> trigger\_post\_change\_hook(
> File "/usr/lib/python3/dist-packages/yunohost/settings.py", line 291, in trigger\_post\_change\_hook
> f(setting\_name, old\_value, new\_value)
> File "/usr/lib/python3/dist-packages/yunohost/settings.py", line 345, in reconfigure\_ssh\_and\_fail2ban
> firewall\_reload()
> File "/usr/lib/python3/dist-packages/yunohost/firewall.py", line 566, in firewall\_reload
> if firewall.apply(upnp=not skip\_upnp):
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/usr/lib/python3/dist-packages/yunohost/firewall.py", line 184, in apply
> if not self.config\["tcp"\]\[ssh\_port\]\["open"\]:
> ~~~~~~~~~~~~~~~~~~ ^^^^^^^^^^
> KeyError: 2323
> 
> \`\`\`
> 
> \### Expected behavior
> 
> No error, ssh port changed and functional
> 
> \### Logs
> 
> https://paste.yunohost.org/raw/egomagewuj

---

<div class="post-metadata">

**Author:** ![otm33](https://forum.yunohost.org/user_avatar/forum.yunohost.org/otm33/32/11941_2.png) [@otm33](https://forum.yunohost.org/u/otm33)\
**Post date:** [October 16, 2025, 10:49pm UTC](https://forum.yunohost.org/t/changing-ssh-port-raises-error-firewall-is-not-updated/40399/6 "2025-10-16T22:49:33Z")

</div>

> [@tinder](#):
>
> File “/usr/lib/python3/dist-packages/yunohost/firewall.py”, line 184, in apply  
> if not self.config[“tcp”][ssh\_port][“open”]:
> 
> `KeyError: 123`

Hi @tinder

Yes, it fails if chosen port is not yet listed in `firewall.yml`. PR submitted. We’ll see…

---

<div class="post-metadata">

**Author:** ![Veronique22](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/v/ba8739/32.png) [@Veronique22](https://forum.yunohost.org/u/Veronique22)\
**Post date:** [October 16, 2025, 11:02pm UTC](https://forum.yunohost.org/t/changing-ssh-port-raises-error-firewall-is-not-updated/40399/7 "2025-10-16T23:02:09Z")

</div>

Hey @tinder,

yeah, that behavior makes sense — YunoHost tries to reload the firewall before the new port gets registered, which triggers the KeyError when it’s missing from firewall.yml.

Until the PR gets merged, your workaround (manually opening the new port before changing it) is the right approach.  
Alternatively, you can also edit /etc/yunohost/firewall.yml and add the new port entry under tcp: before running the settings set command — that avoids the crash too.

Glad to see it’s already tracked on GitHub 👍

---

<div class="post-metadata">

**Author:** ![otm33](https://forum.yunohost.org/user_avatar/forum.yunohost.org/otm33/32/11941_2.png) [@otm33](https://forum.yunohost.org/u/otm33)\
**Post date:** [October 18, 2025, 8:26pm UTC](https://forum.yunohost.org/t/changing-ssh-port-raises-error-firewall-is-not-updated/40399/8 "2025-10-18T20:26:21Z")

</div>

PR merged. Upgrade to latest version `12.1.29` fixes this issue.

---

<div class="post-metadata">

**Author:** ![tinder](https://forum.yunohost.org/user_avatar/forum.yunohost.org/tinder/32/11441_2.png) [@tinder](https://forum.yunohost.org/u/tinder)\
**Post date:** [October 21, 2025, 3:48am UTC](https://forum.yunohost.org/t/changing-ssh-port-raises-error-firewall-is-not-updated/40399/9 "2025-10-21T03:48:08Z")

</div>

Oh, that’s wonderful! Thank you so much! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://forum.yunohost.org/uploads/default/original/2X/f/f59fe8e3ee6b100b4f574d30d6e30479c68b89f0.png) [@system](https://forum.yunohost.org/u/system)\
**Post date:** [November 20, 2025, 3:48am UTC](https://forum.yunohost.org/t/changing-ssh-port-raises-error-firewall-is-not-updated/40399/10 "2025-11-20T03:48:22Z")

</div>

Closed on November 20, 2025, 3:48am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
