Replies: 10 comments 3 replies
-
|
Hi Thanks for taking the time to look through the script and write this up! These are all really solid catches and make a lot of sense. I've just pushed updates addressing all three of your points to the
I want to test these changes and edge cases thoroughly, so I'm keeping them in the Thanks again for the suggestions! Cheers |
Beta Was this translation helpful? Give feedback.
-
|
Good to hear, the ideas were worth considering. However, I was thinking to put all changes to the sshd_config into cossesponding files in the config.d, not only to put the hardening on top. Anyway, I am currently facing a problem, when testing this on my test-server: |
Beta Was this translation helpful? Give feedback.
-
|
maybe i could change the ss command to
it should ignore X11 display ports. |
Beta Was this translation helpful? Give feedback.
-
|
Also, I like your suggestion i will change port override with this if [[ "$SSH_SERVICE" == "ssh.socket" ]]; then
print_info "Configuring SSH socket to listen on port $SSH_PORT..."
mkdir -p /etc/systemd/system/ssh.socket.d
printf '%s\n' "[Socket]" "ListenStream=" "ListenStream=$SSH_PORT" > /etc/systemd/system/ssh.socket.d/override.conf
elif [[ $ID != "ubuntu" ]] || dpkg --compare-versions "$(lsb_release -rs)" lt "24.04"; then
print_info "Configuring SSH service to listen on port $SSH_PORT via systemd..."
mkdir -p /etc/systemd/system/${SSH_SERVICE}.d
printf '%s\n' "[Service]" "ExecStart=" "ExecStart=/usr/sbin/sshd -D -p $SSH_PORT" > /etc/systemd/system/${SSH_SERVICE}.d/override.conf
fi
# port override and hardening to a single config file
print_info "Applying SSH hardening and port configuration to drop-in file..."
mkdir -p /etc/ssh/sshd_config.d
tee /etc/ssh/sshd_config.d/10-hardening.conf > /dev/null <<EOF
Port $SSH_PORT
PermitRootLogin no
PasswordAuthentication no |
Beta Was this translation helpful? Give feedback.
-
|
Another problem: When rolling back, because confirming ssh doesn't work after the changes (or in my case unintentionally hitting no), the complete ssh seems broken and it does not seem to listen to any ip4 ports any more, |
Beta Was this translation helpful? Give feedback.
-
|
ip6 still works however |
Beta Was this translation helpful? Give feedback.
-
|
oh i think i have seen this in past testing and didn't know how to fix it. I will have a look at this again i think in effort to support different Ubuntu versions this has become overly complicated. I will look at this again. |
Beta Was this translation helpful? Give feedback.
-
|
Can I please check what system you were testing this on? Was this issue on Ubuntu 22.04 or later? |
Beta Was this translation helpful? Give feedback.
-
|
This was on 24.04.4. What I do not yet understand is why it stops listening on ip4 ports and why i cannot persuade it at all to restart doing it. |
Beta Was this translation helpful? Give feedback.
-
|
I have now tried your updated version 0.80.1and that works as intended, including timeout and rollback. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there!
Thanks for this very nice script!
I have two suggestions for further improvement:
This would be to revert everything in case the user does not confirm possibility to login in time, e.g. due to a disconnect from the active session. The same could apply for 2fa setup
In caase of an existing user - as far as I have seen - there is no additional check, if a ssh key actually exists and is working.
And a small thing to think about:
Might it be beneficial to actually perform changes to sshd config in a low-lexical-order file in sshd_config.d altogether, instead of changing the default config? So as to avoid the first-mention-wins problem?
Cheers
AV
Beta Was this translation helpful? Give feedback.
All reactions