More options: to Prevent overwriting the file:
Method 1: Probably the best option. Use a Configuration Directory. Modern OpenSSH versions (8.2+) support an include directive. This is the cleanest approach.
Create a drop-in file: Put your custom settings in a separate file, such as /etc/ssh/sshd_config.d/custom.conf. The rule: Package updates will not touch files inside this directory. Verification: Ensure the line Include /etc/ssh/sshd_config.d/*.conf
is active at the top of your main /etc/ssh/sshd_config file.
Method 2: Lock the File (Alternative) You can force the filesystem to make the file immutable so nothing can change it.
Lock the file: Run sudo chattr +i /etc/ssh/sshd_config.
Unlock for edits: Run sudo chattr -i /etc/ssh/sshd_config
when you need to make intentional changes.
Method 3: Tell Apt to Ignore Updates. If you are on a Debian-based system, you can force the package manager to always keep your local version.Add this line to /etc/apt/apt.conf.d/local: UCF_FORCE_CONFFOLD=true