From a214efc6ae2a8570ed7775a09987e230a596d670 Mon Sep 17 00:00:00 2001 From: 247LIKE <54342887+247like@users.noreply.github.com> Date: Fri, 12 Dec 2025 19:51:43 +0800 Subject: [PATCH] Revise README for language and formatting updates Updated language options and improved formatting in README. --- README.md | 143 +++++++++++------------------------------------------- 1 file changed, 28 insertions(+), 115 deletions(-) diff --git a/README.md b/README.md index 904825b..441e536 100644 --- a/README.md +++ b/README.md @@ -9,130 +9,40 @@

- 📖 English | 📖 中文文档 + 🇨🇳 中文文档 | 🇺🇸 English

--- -
- -## 📖 English - -A production-ready, POSIX-compliant shell script designed to initialize Linux servers and harden SSH security in minutes. - -It safely handles **SSH key deployment**, **port changing**, **user creation**, **TCP BBR enablement**, and **system updates**, while ensuring compatibility across Debian, Ubuntu, CentOS, RHEL, and Alpine Linux. - -### ✨ Key Features - -* **Universal Compatibility**: Works flawlessly on **Debian 10/11/12**, **Ubuntu**, **CentOS 7/8/9**, **Alma/Rocky**, and **Alpine Linux**. -* **POSIX Compliant**: Written in pure `/bin/sh`. No `bash` dependency. Runs perfectly on `dash` (Debian) and `ash` (Alpine/Busybox). -* **Safety Architecture**: - * **Managed Config Block**: Inserts configuration at the **top** of `sshd_config` to strictly override vendor defaults (bypasses the Debian 12 `Include` trap). - * **Atomic Verification**: Validates config with `sshd -t` before restarting. Automatically rolls back on failure to prevent downtime. - * **Anti-Lockout**: If SSH keys fail to deploy, it **will not** disable password login, ensuring you don't lose access. - * **Firewall Awareness**: Automatically detects and configures `ufw` or `firewalld` if port is changed. -* **Smart Interactions**: - * Fetches public keys from **GitHub**, **URL**, or **Direct Paste**. - * **Random High Port**: Generates a random port between 20000-60000 and checks for availability using `ss`/`netstat`. - * **System Update** & **TCP BBR**: Optional one-click optimization. - -### 🚀 Quick Start - -Run the following command as **root**. - -#### Standard Run (Interactive) -```bash -curl -fsSL [https://raw.githubusercontent.com/247like/linux-ssh-init-sh/main/init.sh](https://raw.githubusercontent.com/247like/linux-ssh-init-sh/main/init.sh) -o init.sh && chmod +x init.sh && ./init.sh -```` - -#### Force English UI - -```bash -./init.sh --lang=en -``` - -### ⚙️ Command Line Arguments - -The script accepts the following arguments to control its behavior: - -| Argument | Description | -| :--- | :--- | -| `--lang=en` | Force the interactive interface to use **English**. | -| `--lang=zh` | Force the interactive interface to use **Chinese** (Default behavior asks if not specified). | -| `--strict` | **Strict Mode**. If enabled, the script will **exit immediately** if any critical step (like downloading keys or generating a port) fails, instead of falling back to defaults. Recommended for CI/CD or automated pipelines. | - -### ⚙️ Strict Mode vs. Normal Mode - -| Feature | Normal Mode (Default) | Strict Mode (`--strict`) | -| :--- | :--- | :--- | -| **Philosophy** | **"Don't Lockout"** (Best Effort) | **"Compliance First"** (Zero Tolerance) | -| **Key Failure** | If key download fails, script **keeps Password Auth enabled** and warns you. | Script **exits immediately**. No changes applied. | -| **Port Failure** | If random port generation fails, it falls back to **Port 22**. | Script **exits immediately**. | -| **Use Case** | Manual setup, unstable networks. | CI/CD pipelines, high-security requirements. | - -### 💡 Examples - -**1. Standard interactive installation (English):** - -```bash -./init.sh --lang=en -``` - -**2. Strict mode for high-security requirements:** -*If the GitHub key cannot be downloaded, the script will abort rather than falling back to password login.* - -```bash -./init.sh --strict -``` - -### 🛠️ Technical Logic - -1. **Dependency Check**: Auto-detects package manager (`apt`, `yum`, `apk`) and installs minimal dependencies (`curl`, `sudo`, `openssh-server`). -2. **User Setup**: Creates the specified user (if not root) and grants password-less `sudo` privileges. -3. **Key Deployment**: Fetches keys, validates format, fixes `.ssh` permissions (SELinux context safe), and writes to `authorized_keys`. -4. **Config Writing**: - * Backs up `sshd_config`. - * Removes old script-managed blocks. - * Writes a new block at the **beginning** of the file to ensure priority over `Include` directives. -5. **Finalization**: Validates config syntax, restarts SSH service, and applies BBR/Updates if requested. - ------ - -\
\ - -## 📖 中文文档 - 一个生产就绪、符合 POSIX 标准的 Shell 脚本,用于 Linux 服务器的一键初始化与 SSH 安全加固。 该脚本可自动完成 **SSH 密钥配置**、**修改端口**、**创建用户**、**开启 BBR** 以及 **系统更新**,并完美兼容 Debian, Ubuntu, CentOS, RHEL 以及 Alpine Linux。 ### ✨ 核心特性 - * **全平台兼容**: 完美支持 **Debian 10/11/12**, **Ubuntu**, **CentOS 7/8/9**, **Alma/Rocky**, 以及 **Alpine Linux**。 - * **POSIX 标准**: 纯 `/bin/sh` 编写,无需安装 `bash`。在 `dash` (Debian) 和 `ash` (Alpine/Busybox) 上稳定运行。 - * **安全设计架构**: - * **头部管理块 (Managed Block)**: 将安全配置插入 `sshd_config` 的**最顶部**,从而覆盖 Debian 12 默认的 `Include` 配置陷阱。 - * **原子化验证**: 修改后自动执行 `sshd -t` 校验,若校验失败则**自动回滚**配置,防止服务挂掉。 - * **防失联机制**: 如果 SSH 公钥下载或部署失败,脚本**不会**强制关闭密码登录,确保你不会把自己锁在门外。 - * **防火墙感知**: 修改端口时,自动识别并放行 `ufw` 或 `firewalld`。 - * **智能交互**: - * 支持从 **GitHub**、**URL** 自动拉取公钥,或支持多行**手动粘贴**。 - * **随机高位端口**: 自动生成 20000-60000 之间的随机端口,并使用 `ss`/`netstat` 检测占用情况。 - * **系统优化**: 可选开启 **TCP BBR** 拥塞控制及系统软件更新。 +* **全平台兼容**: 完美支持 **Debian 10/11/12**, **Ubuntu**, **CentOS 7/8/9**, **Alma/Rocky**, 以及 **Alpine Linux**。 +* **POSIX 标准**: 纯 `/bin/sh` 编写,无需安装 `bash`。在 `dash` (Debian) 和 `ash` (Alpine/Busybox) 上稳定运行。 +* **安全设计架构**: + * **头部管理块 (Managed Block)**: 将安全配置插入 `sshd_config` 的**最顶部**,从而覆盖 Debian 12 默认的 `Include` 配置陷阱。 + * **原子化验证**: 修改后自动执行 `sshd -t` 校验,若校验失败则**自动回滚**配置,防止服务挂掉。 + * **防失联机制**: 如果 SSH 公钥下载或部署失败,脚本**不会**强制关闭密码登录,确保你不会把自己锁在门外。 + * **防火墙感知**: 修改端口时,自动识别并放行 `ufw` 或 `firewalld`。 +* **智能交互**: + * 支持从 **GitHub**、**URL** 自动拉取公钥,或支持多行**手动粘贴**。 + * **随机高位端口**: 自动生成 20000-60000 之间的随机端口,并使用 `ss`/`netstat` 检测占用情况。 + * **系统优化**: 可选开启 **TCP BBR** 拥塞控制及系统软件更新。 ### 🚀 快速开始 请以 **root** 身份运行。 #### 标准运行 (交互式) - ```bash curl -fsSL [https://raw.githubusercontent.com/247like/linux-ssh-init-sh/main/init.sh](https://raw.githubusercontent.com/247like/linux-ssh-init-sh/main/init.sh) -o init.sh && chmod +x init.sh && ./init.sh ``` #### 强制中文界面 - ```bash ./init.sh --lang=zh ``` @@ -159,14 +69,12 @@ curl -fsSL [https://raw.githubusercontent.com/247like/linux-ssh-init-sh/main/ini ### 💡 使用示例 **1. 交互式初始化 (中文):** - ```bash ./init.sh --lang=zh ``` **2. 严格模式 (自动化/高安全场景):** *如果公钥下载失败,脚本将直接报错退出,而不会允许使用密码登录。* - ```bash ./init.sh --strict ``` @@ -177,22 +85,27 @@ curl -fsSL [https://raw.githubusercontent.com/247like/linux-ssh-init-sh/main/ini 2. **用户管理**: 创建指定用户(若非 root)并配置免密 Sudo 权限。 3. **密钥部署**: 部署 SSH 公钥,自动修正 `.ssh` 目录权限,支持去重。 4. **SSH 加固**: - * 备份 `sshd_config`。 - * 清理旧的脚本配置块。 - * 在文件**头部**写入新的安全配置(禁密码、改端口等),确保优先级最高。 + * 备份 `sshd_config`。 + * 清理旧的脚本配置块。 + * 在文件**头部**写入新的安全配置(禁密码、改端口等),确保优先级最高。 5. **收尾工作**: 验证配置语法,重启 SSH 服务,并根据选择应用 BBR 或系统更新。 ------ +--- -### ⚠️ Disclaimer / 免责声明 - -This script modifies critical system configurations (SSH). While it includes safety checks and rollbacks, please ensure you have a backup method (VNC/Console) to access your server in case of network issues or configuration errors. +### ⚠️ 免责声明 本脚本会修改核心系统配置(SSH)。虽然脚本内置了多重安全检查和回滚机制,但请务必确保你拥有服务器的备用访问方式(如 VNC 控制台),以防网络波动或配置意外导致的连接中断。 -### License +### 📄 开源协议 -MIT License +本项目采用 [MIT License](LICENSE) 开源。 -``` -``` +--- + +
+ +如果您觉得这个工具好用,请给一颗 ⭐ 星! + +[报告问题](https://github.com/247like/linux-ssh-init-sh/issues) · [功能建议](https://github.com/247like/linux-ssh-init-sh/issues) + +