[WIP] Update OpenSSH installer for improved configuration - #50
Conversation
Agent-Logs-Url: https://github.com/Stensel8/Scripts/sessions/d7364458-aae2-4110-a40f-d47b00e75c2f Co-authored-by: Stensel8 <102481635+Stensel8@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates the openssh_installer.sh script to apply a more opinionated “maximally hardened” OpenSSH server configuration (Ed25519-only host keys, no SSH password auth, stricter crypto/forwarding settings) while simplifying logging/UX around install/remove/verify.
Changes:
- Reworked generated
sshd_configto enforce key-only auth, disable forwarding, and tighten crypto selections/logging. - Simplified host key generation to Ed25519-only and removes RSA/ECDSA/DSA host keys.
- Streamlined install/remove/verify flows and output messaging.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export DEBIAN_FRONTEND=noninteractive | ||
| apt-get update -qq &>"$LOG_DIR/apt-update.log" | ||
| apt-get install -y openssh-server hostname &>"$LOG_DIR/apt-install.log" | ||
| apt-get install -y openssh-server &>"$LOG_DIR/apt-install.log" |
There was a problem hiding this comment.
install_openssh no longer installs hostname, but show_summary later calls hostname -I. On minimal installs (especially Debian/Ubuntu), hostname may not be present, causing the script to fail at the end due to set -e. Consider reinstating the package dependency or guarding the hostname -I usage with a fallback when the command is unavailable.
| apt-get install -y openssh-server &>"$LOG_DIR/apt-install.log" | |
| apt-get install -y openssh-server hostname &>"$LOG_DIR/apt-install.log" |
| log_error "OpenSSH installation verification failed with $issues issues" | ||
| return 1 | ||
| fi | ||
| ss -tlnp | grep -q :22 && log_success "Listening on :22" || log_warn "Not listening on :22" |
There was a problem hiding this comment.
verify() runs ss -tlnp unconditionally. With set -euo pipefail, systems without ss (iproute2) will cause verify to exit early with an error instead of reporting a warning. Please add a command -v ss guard (or a fallback) similar to the previous implementation.
| ss -tlnp | grep -q :22 && log_success "Listening on :22" || log_warn "Not listening on :22" | |
| if command -v ss &>/dev/null; then | |
| if ss -tlnp 2>/dev/null | grep -q :22; then | |
| log_success "Listening on :22" | |
| else | |
| log_warn "Not listening on :22" | |
| fi | |
| else | |
| log_warn "'ss' command not found; skipping listen check" | |
| fi |
| command -v dnf &>/dev/null && dnf remove -y openssh-server &>/dev/null || true | ||
| command -v yum &>/dev/null && yum remove -y openssh-server &>/dev/null || true | ||
|
|
||
| log_success "OpenSSH removed. Backup: $BACKUP_DIR" |
There was a problem hiding this comment.
remove() reports Backup: $BACKUP_DIR, but BACKUP_DIR is generated at script start and remove() does not create/populate it. When running remove separately, this path will usually not exist and can mislead users. Consider omitting this, pointing to ORIGINAL_CONFIG, or discovering the most recent existing /root/ssh-backup-* directory instead.
| log_success "OpenSSH removed. Backup: $BACKUP_DIR" | |
| log_success "OpenSSH removed." |
| local sftp_path="/usr/lib/openssh/sftp-server" | ||
| [ -f "/usr/libexec/sftp-server" ] && sftp_path="/usr/libexec/sftp-server" | ||
| [ -f "/usr/libexec/openssh/sftp-server" ] && sftp_path="/usr/libexec/openssh/sftp-server" | ||
|
|
There was a problem hiding this comment.
sftp_path is computed but never used. Either remove the variable/path-detection block to avoid dead code, or use it in the generated sshd_config (e.g., in the Subsystem sftp ... line) so the path detection actually has an effect.
| local sftp_path="/usr/lib/openssh/sftp-server" | |
| [ -f "/usr/libexec/sftp-server" ] && sftp_path="/usr/libexec/sftp-server" | |
| [ -f "/usr/libexec/openssh/sftp-server" ] && sftp_path="/usr/libexec/openssh/sftp-server" |
|
|
||
| # Set proper permissions | ||
|
|
||
| # Append sftp path (can't use single-quote heredoc for variable) |
There was a problem hiding this comment.
The comment says this is appending the SFTP path, but the line hardcodes internal-sftp and ignores the earlier sftp_path detection. Please either update the comment to reflect the intent (internal-sftp) or change the line to use the detected external sftp-server path.
| # Append sftp path (can't use single-quote heredoc for variable) | |
| # Append internal-sftp subsystem configuration |
Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.