Skip to content

Fix server setup safety and docker tools - #6

Merged
SuperNG6 merged 1 commit into
mainfrom
fix/server-setup-hardening-docker-tools
Jun 4, 2026
Merged

Fix server setup safety and docker tools#6
SuperNG6 merged 1 commit into
mainfrom
fix/server-setup-hardening-docker-tools

Conversation

@SuperNG6

@SuperNG6 SuperNG6 commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • harden SSH password/port changes with managed drop-in config and effective sshd validation
  • make swap removal safer, avoid network restarts in DNS setup, and move Fail2ban SSH jail into jail.d
  • validate kernel tuning inputs, roll back failed sysctl applies, fix Docker install args, and improve Docker helper commands/completion

Verification

  • bash -n server-setup.sh add_docker_tools.sh configure_fail2ban.sh manage_xanmod_kernel.sh optimize_kernel_parameters.sh set_dns_via_dhclient.sh docker_tools/*.sh
  • shellcheck -S warning server-setup.sh add_docker_tools.sh configure_fail2ban.sh manage_xanmod_kernel.sh optimize_kernel_parameters.sh set_dns_via_dhclient.sh docker_tools/*.sh
  • git diff --check
  • simulated dlogs/dexec container completion test

Copilot AI review requested due to automatic review settings June 4, 2026 09:30
@SuperNG6
SuperNG6 merged commit 04bf7e9 into main Jun 4, 2026
1 check passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31d2eb2217

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server-setup.sh
OS_TYPE=""

SSHD_CONFIG="/etc/ssh/sshd_config"
SSHD_MANAGED_CONFIG="/etc/ssh/sshd_config.d/99-linux-setup.conf"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use a drop-in that precedes existing SSH snippets

On hosts that already have an earlier /etc/ssh/sshd_config.d/*.conf snippet setting Port or password authentication (for example distro/cloud 50-*.conf files), this 99-... file is read after them, and sshd_config(5) says “for each keyword, the first obtained value will be used.” In that environment the values written by options 3/4 are ignored, verify_ssh_* rolls the change back, and those SSH menu actions become unusable; the managed snippet needs to sort before existing defaults or otherwise remove/override conflicting earlier snippets.

Useful? React with 👍 / 👎.

Comment thread server-setup.sh
echo "# Managed by linux-setup.sh"
echo "# Do not edit manually unless you stop using the script."
if [ -n "$final_port" ]; then
echo "Port $final_port"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep Fail2ban port detection in sync with drop-in

After option 4 succeeds, the new SSH port is now written only to /etc/ssh/sshd_config.d/99-linux-setup.conf, but configure_fail2ban.sh:get_ssh_port still greps only /etc/ssh/sshd_config and falls back to 22. If a user changes SSH to a non-22 port and then configures Fail2ban from this toolbox, the generated jail protects the wrong port and leaves the actual SSH listener unprotected.

Useful? React with 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens a Linux server bootstrap toolkit by making SSH/DNS/sysctl changes safer for remote hosts and by improving Docker helper scripts (safer argument handling + container selection/completion).

Changes:

  • Harden SSH configuration changes using an sshd drop-in file, plus validation/rollback logic.
  • Make DNS and swap operations safer for remote servers (avoid network restarts; safer swap removal flow).
  • Improve Docker helper scripts (remove eval, add argument-based container selection and shell completion).

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
set_dns_via_dhclient.sh Adds environment checks and avoids automatic network restarts; provides manual apply guidance.
server-setup.sh Introduces sshd drop-in management + validation/rollback, safer swap removal, and Docker install arg handling.
README.md Fixes command examples / markdown formatting for install URLs.
optimize_kernel_parameters.sh Validates inputs and adds rollback when sysctl -p fails; updates tcp_moderate_rcvbuf setting.
manage_xanmod_kernel.sh Minor debug output adjustment.
docker_tools/docker_utils.sh Adds compose runner + container resolution helpers (but compose detection needs fixing).
docker_tools/docker_aliases.sh Replaces aliases with functions for dlogs/dexec and adds completion.
docker_tools/dlogs.sh Supports optional container arg (name or index) instead of always prompting.
docker_tools/dexec.sh Supports optional container arg (name or index) instead of always prompting.
docker_tools/dcstats.sh Adds ShellCheck suppression for sourced globals.
docker_tools/dcrestart.sh Adds ShellCheck suppression for sourced globals; minor formatting.
docker_tools/dcps.sh Adds ShellCheck suppression for sourced globals.
docker_tools/dclogs.sh Adds ShellCheck suppression for sourced globals.
docker_tools/dc.sh Removes eval and runs compose command safely with preserved argv boundaries.
configure_fail2ban.sh Moves SSH jail config into jail.d drop-in file and adjusts related messaging/backup behavior.
add_docker_tools.sh Updates generated aliases to functions and adds completion for container names.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server-setup.sh
Comment on lines 1030 to +1033
echo "正在修改 SSH 端口为 $new_port..."
# 备份配置文件
cp "$sshd_config" "${sshd_config}.bak"
# 修改或添加 Port 配置
if grep -q "^\s*Port" "$sshd_config"; then
sed -i "s/^\s*Port.*/Port $new_port/" "$sshd_config"
else
echo "Port $new_port" >>"$sshd_config"
backup_dir=$(backup_ssh_state)
ensure_sshd_dropin_include
write_ssh_managed_config "$new_port" "keep"
Comment thread server-setup.sh
Comment on lines +693 to +697
if [ -f /etc/fstab ]; then
tmp_fstab=$(mktemp)
awk -v target="$item" '$1 != target {print}' /etc/fstab >"$tmp_fstab"
mv "$tmp_fstab" /etc/fstab
fi
Comment thread configure_fail2ban.sh
Comment on lines 249 to +253
local ban_time_seconds=$((ban_time_hours * 3600))
local jail_local="/etc/fail2ban/jail.local"
local jail_local="/etc/fail2ban/jail.d/sshd-linux-setup.local"
local custom_comment="# SSH protection configured by fail2ban.sh script"
local log_path=$(detect_ssh_log_path)
local os_type=$(get_os_info)
local log_path
log_path=$(detect_ssh_log_path)
Comment thread server-setup.sh
Comment on lines +148 to +155
ensure_sshd_dropin_include() {
if head -n 1 "$SSHD_CONFIG" | grep -Eiq '^[[:space:]]*Include[[:space:]]+/etc/ssh/sshd_config\.d/\*\.conf'; then
return 0
fi

echo "正在将 sshd_config drop-in Include 放到文件顶部,确保脚本管理的配置优先生效。"
sed -i '1i Include /etc/ssh/sshd_config.d/*.conf' "$SSHD_CONFIG"
}
Comment on lines +17 to +21
run_docker_compose() {
if [ "$compose_cmd" = "docker compose" ]; then
docker compose "$@"
else
docker-compose "$@"
@SuperNG6

SuperNG6 commented Jun 4, 2026

Copy link
Copy Markdown
Owner Author

@copilot review代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants