mirror of
https://github.com/konstruktoid/hardening.git
synced 2026-04-25 16:55:53 +03:00
[GH-ISSUE #536] [BUG] SSH service is not restarted in ubuntu 24.04 #86
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @GauthierPLM on GitHub (Dec 10, 2024).
Original GitHub issue: https://github.com/konstruktoid/hardening/issues/536
Originally assigned to: @konstruktoid on GitHub.
Describe the bug
During setup, the ssh service is not properly restarted at the end of the setup process.
If SSH port has been changed, we are locked outside the machine as ufw only allows the new port but sshd is still listening on the old port.
The service name is now
sshand no moresshd, maybe this causes the issue?To Reproduce
anyasFW_ADMINvalue.Expected behavior
ssh.serviceshould be properly restarted.System (lsb_release -a):
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04.1 LTS
Release: 24.04
Codename: noble
@konstruktoid commented on GitHub (Dec 10, 2024):
Thanks for creating the issue @GauthierPLM, I believe it's fixed now.
@GauthierPLM commented on GitHub (Dec 17, 2024):
Hi @konstruktoid
I tested again today and while there was no warning about sshd service not being found, the service wasn't restarted and I had to restart it manually.
@konstruktoid commented on GitHub (Dec 17, 2024):
So the fix didn't work?
@GauthierPLM commented on GitHub (Dec 17, 2024):
It does not indeed.
@konstruktoid commented on GitHub (Dec 18, 2024):
Can you try this diff?
@GauthierPLM commented on GitHub (Dec 20, 2024):
Tried today at 12h30 on an existing machine (not yet hardened), and the fix didn't solve the issue. The service still listen on port 22:
I had to restart the service myself.
@konstruktoid commented on GitHub (Dec 20, 2024):
don't really have an idea why this is happening, will continue to test
@GauthierPLM commented on GitHub (Dec 20, 2024):
I don't know if it will help, but the machines are ARN cloud servers from Hetzner, running Ubuntu 24.04.
This is my cloud-init.yaml file:
@filisko commented on GitHub (Apr 16, 2025):
same here... crazy that this is hapenning, i had to restart my server and had downtime on an important service :/
@GauthierPLM commented on GitHub (Apr 16, 2025):
@filisko until it's fixed, you can restart the SSH service immediately after running the hardening script:
̀ sudo bash ubuntu.sh && sudo systemctl restart ssh.service`
@konstruktoid commented on GitHub (Apr 17, 2025):
@filisko unless there's an kernel update, you probably don't need to restart your server at all.
@GauthierPLM yeah, I'll see if I can add that some how, haven't really seen another workaround
@Dimi8146 commented on GitHub (Jul 30, 2025):
I could replicate this issue & it annoyed me enough to look into it a bit.
I found a suspicious new sshd_config.d folder with special characters at the end after I finished running the hardening script. Inside I found the hardening.conf file buried in a duplicate /etc/ssh/sshd_config.d/ folder path. But what was annoying was this couldn't be replicated at home, it only occurred on cloud infra.
So, I hunted down the pathfinding logic in sshdconfig, copied it to a cloud shell environment, & it initially looked fine - except when I deleted the variable it was assigned to & looked at the output to the terminal directly:
I fed this into gpt, along with what I was originally having a problem with and the context of the codebase, then asked it why multiple lines returned when I expected one. It gave me grep/awk + command substitution as the reason for why there was a newline being carried through into dirname, and ultimately creating the unseen folder containing the intended ssh hardening changes. It also gave the following suggestion:
Not sure if the reasoning is accurate, but I patched sshdconfig with the below diff & the next use ran fine.
@konstruktoid commented on GitHub (Jul 30, 2025):
nicely done @Dimi8146, could you submit a PR?
@Dimi8146 commented on GitHub (Jul 30, 2025):
ah! I must've misremembered the details of my variable troubles, this spanned two days.
Thank you for replicating, that was my main hesitation.
https://github.com/konstruktoid/hardening/pull/642
@konstruktoid commented on GitHub (Aug 7, 2025):
this should be fixed with the help of @Dimi8146 and #642