diff options
| author | Christian Cleberg <[email protected]> | 2023-12-02 23:27:35 -0600 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2023-12-02 23:27:35 -0600 |
| commit | 3d4da5ac6000a4871c5caa80d1e61f2782da3069 (patch) | |
| tree | 29f36b50823d22f4c7df0a3db3ede83192ae649f /blog/2023-10-15-alpine-ssh-hardening.org | |
| parent | dcf0186e16b6ac8f0e00a3aeb9734421ce548177 (diff) | |
| download | cleberg.net-3d4da5ac6000a4871c5caa80d1e61f2782da3069.tar.gz cleberg.net-3d4da5ac6000a4871c5caa80d1e61f2782da3069.tar.bz2 cleberg.net-3d4da5ac6000a4871c5caa80d1e61f2782da3069.zip | |
feat: finish converting md to org
Diffstat (limited to 'blog/2023-10-15-alpine-ssh-hardening.org')
| -rw-r--r-- | blog/2023-10-15-alpine-ssh-hardening.org | 94 |
1 files changed, 54 insertions, 40 deletions
diff --git a/blog/2023-10-15-alpine-ssh-hardening.org b/blog/2023-10-15-alpine-ssh-hardening.org index 2ba483d..03a3ba7 100644 --- a/blog/2023-10-15-alpine-ssh-hardening.org +++ b/blog/2023-10-15-alpine-ssh-hardening.org @@ -1,60 +1,74 @@ -+++ -date = 2023-10-16T00:20:45+00:00 -title = "SSH Hardening for Alpine Linux" -description = "A quick guide to hardening SSH on Alpine Linux." -+++ - -## Overview +#+title: SSH Hardening for Alpine Linux +#+date: 2023-10-16 +** Overview +:PROPERTIES: +:CUSTOM_ID: overview +:END: This guide follows the standard -[ssh-audit](https://www.ssh-audit.com/hardening_guides.html) hardening guide, -tweaked for Alpine Linux. - -## Hardening Guide +[[https://www.ssh-audit.com/hardening_guides.html][ssh-audit]] hardening +guide, tweaked for Alpine Linux. -These steps must be performed as root. You can try to use `doas` or `sudo`, -but there may be issues. +** Hardening Guide +:PROPERTIES: +:CUSTOM_ID: hardening-guide +:END: +These steps must be performed as root. You can try to use =doas= or +=sudo=, but there may be issues. 1. Re-generate the RSA and ED25519 keys -```sh + +#+begin_src sh rm /etc/ssh/ssh_host_* ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N "" ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" -``` -2. Remove small Diffie-Hellman moduli -```sh +#+end_src + +2. [@2] Remove small Diffie-Hellman moduli + +#+begin_src sh awk '$5 >= 3071' /etc/ssh/moduli > /etc/ssh/moduli.safe mv /etc/ssh/moduli.safe /etc/ssh/moduli -``` -3. Enable the RSA and ED25519 HostKey directives in the /etc/ssh/sshd_config -file -```sh +#+end_src + +3. [@3] Enable the RSA and ED25519 HostKey directives in the + /etc/ssh/sshd_config file + +#+begin_src sh sed -i 's/^\#HostKey \/etc\/ssh\/ssh_host_\(rsa\|ed25519\)_key$/HostKey \/etc\/ssh\/ssh_host_\1_key/g' /etc/ssh/sshd_config -``` -4. Restrict supported key exchange, cipher, and MAC algorithms -```sh +#+end_src + +4. [@4] Restrict supported key exchange, cipher, and MAC algorithms + +#+begin_src sh echo -e "\n# Restrict key exchange, cipher, and MAC algorithms, as per sshaudit.com\n# hardening guide.\nKexAlgorithms [email protected],curve25519-sha256,[email protected],diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256\nCiphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr\nMACs [email protected],[email protected],[email protected]\nHostKeyAlgorithms ssh-ed25519,[email protected],[email protected],[email protected],rsa-sha2-512,[email protected],rsa-sha2-256,[email protected]" > /etc/ssh/sshd_config.d/ssh-audit_hardening.conf -``` -5. Include the /etc/ssh/sshd_config.d directory -```sh +#+end_src + +5. [@5] Include the /etc/ssh/sshd_config.d directory + +#+begin_src sh echo -e "Include /etc/ssh/sshd_config.d/*.conf" > /etc/ssh/sshd_config -``` -6. Restart OpenSSH server -```sh -rc-service sshd restart -``` +#+end_src + +6. [@6] Restart OpenSSH server -## Testing SSH +#+begin_src sh +rc-service sshd restart +#+end_src -You can test the results with the `ssh-audit` python script. +** Testing SSH +:PROPERTIES: +:CUSTOM_ID: testing-ssh +:END: +You can test the results with the =ssh-audit= python script. -```sh +#+begin_src sh pip3 install ssh-audit ssh-audit localhost -``` +#+end_src -If everything succeeded, the results will show as all green. If anything is -yellow, orange, or red, you may need to tweak additional settings. +If everything succeeded, the results will show as all green. If anything +is yellow, orange, or red, you may need to tweak additional settings. - +#+caption: ssh audit +[[https://img.cleberg.net/blog/20231015-ssh-hardening/ssh-audit.png%20%22ssh-audit%22]] |
