docs: Add missing docs for initial host setup
This commit is contained in:
2 files changed
+275
-21
No files matched your search
@@ -10,6 +10,21 @@ Hardened setup for a fresh Debian host from zero to deployment.
|
|||||||
|
|
||||||
{{% steps %}}
|
{{% steps %}}
|
||||||
|
|
||||||
|
### Essential Packages
|
||||||
|
|
||||||
|
Install `sudo` and `docker-ce` first. This is necessary because the subsequent user setup relies on the `docker` group and `sudo` configuration.
|
||||||
|
|
||||||
|
**Install Sudo**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# As root:
|
||||||
|
apt update && apt install sudo -y
|
||||||
|
```
|
||||||
|
|
||||||
|
**Install Docker**
|
||||||
|
|
||||||
|
Follow the [Official Docker Installation Guide for Debian](https://docs.docker.com/engine/install/debian/) to install the latest Docker Engine.
|
||||||
|
|
||||||
### System User & Privileges
|
### System User & Privileges
|
||||||
|
|
||||||
The `adam` user handles all administrative tasks. SSH-key authentication and passwordless `sudo` via the `wheel` group minimize friction while maintaining security.
|
The `adam` user handles all administrative tasks. SSH-key authentication and passwordless `sudo` via the `wheel` group minimize friction while maintaining security.
|
||||||
@@ -17,30 +32,51 @@ The `adam` user handles all administrative tasks. SSH-key authentication and pas
|
|||||||
**Create the Admin User**
|
**Create the Admin User**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# As root:
|
||||||
# Create the user with a bash shell
|
# Create the user with a bash shell
|
||||||
useradd -m -s /bin/bash adam
|
useradd -m -s /bin/bash adam
|
||||||
|
|
||||||
# Create the wheel group (common for cross-distro consistency)
|
# Create the wheel group (common for cross-distro consistency)
|
||||||
groupadd wheel
|
groupadd wheel
|
||||||
|
|
||||||
# Create a modular sudoers file with safety checks
|
# Create a modular sudoers file
|
||||||
# This allows members of 'wheel' to run sudo without a password
|
# This allows members of 'wheel' to run sudo without a password
|
||||||
echo "%wheel ALL=(ALL) NOPASSWD: ALL" | sudo visudo -c -f /etc/sudoers.d/99-root-ermnvldmr
|
echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/99-root-ermnvldmr
|
||||||
|
|
||||||
|
# Validate syntax
|
||||||
|
visudo -c -f /etc/sudoers.d/99-root-ermnvldmr
|
||||||
|
|
||||||
# Add adam to the necessary groups
|
# Add adam to the necessary groups
|
||||||
usermod -aG wheel,docker adam
|
usermod -aG wheel,docker adam
|
||||||
```
|
```
|
||||||
|
|
||||||
### SSH Hardening & Key Management
|
### Swap Setup
|
||||||
|
|
||||||
|
Configure a swap file to ensure system stability during memory-intensive operations.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# As root:
|
||||||
|
# Create a 2GB swap file (adjust size as needed)
|
||||||
|
fallocate -l 2G /swap
|
||||||
|
chmod 600 /swap
|
||||||
|
mkswap /swap
|
||||||
|
swapon /swap
|
||||||
|
|
||||||
|
# Make it permanent
|
||||||
|
echo '/swap none swap sw 0 0' >> /etc/fstab
|
||||||
|
```
|
||||||
|
|
||||||
|
### SSH Access & Hardening
|
||||||
|
|
||||||
Passwords are disabled. Access is strictly via SSH keys.
|
Passwords are disabled. Access is strictly via SSH keys.
|
||||||
|
|
||||||
**Secure SSH Directory**
|
**Authorize Operator Key**
|
||||||
|
|
||||||
Set strict permissions immediately to prevent the SSH daemon from rejecting the keys.
|
Import your local public key to the `adam` user.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Setup directories as root for the adam user
|
# As root:
|
||||||
|
# Setup directories
|
||||||
mkdir -p /home/adam/.ssh
|
mkdir -p /home/adam/.ssh
|
||||||
chmod 700 /home/adam/.ssh
|
chmod 700 /home/adam/.ssh
|
||||||
|
|
||||||
@@ -50,11 +86,24 @@ chmod 600 /home/adam/.ssh/authorized_keys
|
|||||||
chown -R adam:adam /home/adam/.ssh
|
chown -R adam:adam /home/adam/.ssh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Operator Side Access**
|
||||||
|
|
||||||
|
Configure your local machine for easy access to the host.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# ~/.ssh/config on operator side
|
||||||
|
Host daedalus.root.ermnvldmr.com
|
||||||
|
Port 2222
|
||||||
|
User adam
|
||||||
|
IdentityFile ~/.ssh/adam_root_ermnvldmr_com_ed25519
|
||||||
|
```
|
||||||
|
|
||||||
**Harden SSH Daemon**
|
**Harden SSH Daemon**
|
||||||
|
|
||||||
Modify the SSH configuration to change the default port and disable password entry.
|
Modify the SSH configuration to change the default port and disable password entry.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# As root:
|
||||||
# Create a dedicated override config
|
# Create a dedicated override config
|
||||||
cat <<EOF > /etc/ssh/sshd_config.d/99-root-ermnvldmr.conf
|
cat <<EOF > /etc/ssh/sshd_config.d/99-root-ermnvldmr.conf
|
||||||
Port 2222
|
Port 2222
|
||||||
@@ -72,35 +121,34 @@ sshd -t && systemctl restart ssh
|
|||||||
The host requires its own identity to pull updates from the GitHub repository.
|
The host requires its own identity to pull updates from the GitHub repository.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# As root:
|
||||||
# Generate a host-specific SSH key (no passphrase for automation)
|
# Generate a host-specific SSH key (no passphrase for automation)
|
||||||
ssh-keygen -t ed25519 -f /home/adam/.ssh/adam-at-deytenit_github_com_ed25519 -N ""
|
sudo -u adam ssh-keygen -t ed25519 -f /home/adam/.ssh/github_ed25519 -N ""
|
||||||
|
|
||||||
|
# Configure SSH to use this key for GitHub
|
||||||
|
cat <<EOF | sudo -u adam tee /home/adam/.ssh/config
|
||||||
|
Host github.com
|
||||||
|
AddKeysToAgent yes
|
||||||
|
IdentityFile ~/.ssh/github_ed25519
|
||||||
|
EOF
|
||||||
|
|
||||||
# Display the public key to be added to GitHub (Settings > Deploy Keys)
|
# Display the public key to be added to GitHub (Settings > Deploy Keys)
|
||||||
cat /home/adam/.ssh/adam-at-deytenit_github_com_ed25519.pub
|
cat /home/adam/.ssh/github_ed25519.pub
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!TIP]
|
> [!TIP]
|
||||||
> Add the output above to the [GitHub: Repository Deploy Keys](https://github.com/deytenit/root.ermnvldmr.com/settings/keys) with **read access**.
|
> Add the output above to the [GitHub: Repository Deploy Keys](https://github.com/deytenit/root.ermnvldmr.com/settings/keys) with **read access**.
|
||||||
|
|
||||||
### Install Docker Engine
|
|
||||||
|
|
||||||
Install the standard Docker Engine for Debian.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Follow official guide: https://docs.docker.com/engine/install/debian/
|
|
||||||
# Once installed, verify (Adam can run this without sudo now)
|
|
||||||
docker run --rm hello-world
|
|
||||||
```
|
|
||||||
|
|
||||||
### Repository Deployment
|
### Repository Deployment
|
||||||
|
|
||||||
Clone the infrastructure repository and initialize the node.
|
Clone the infrastructure repository and initialize the node.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# As root:
|
||||||
# Setup the service directory
|
# Setup the service directory
|
||||||
export REPO_DIR="/srv/root.ermnvldmr.com"
|
export REPO_DIR="/srv/root.ermnvldmr.com"
|
||||||
sudo mkdir -p $REPO_DIR
|
mkdir -p $REPO_DIR
|
||||||
sudo chown adam:adam $REPO_DIR
|
chown adam:adam $REPO_DIR
|
||||||
|
|
||||||
# Clone as the adam user
|
# Clone as the adam user
|
||||||
sudo -u adam git clone git@github.com:deytenit/root.ermnvldmr.com.git $REPO_DIR
|
sudo -u adam git clone git@github.com:deytenit/root.ermnvldmr.com.git $REPO_DIR
|
||||||
@@ -116,7 +164,9 @@ sudo -u adam ./init.sh
|
|||||||
Run the staged initialization scripts in order:
|
Run the staged initialization scripts in order:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# As root:
|
||||||
# Run the sequence for your specific node
|
# Run the sequence for your specific node
|
||||||
|
cd $REPO_DIR
|
||||||
./$NODE/.host/.scripts/00-base
|
./$NODE/.host/.scripts/00-base
|
||||||
./$NODE/.host/.scripts/10-ufw
|
./$NODE/.host/.scripts/10-ufw
|
||||||
./$NODE/.host/.scripts/20-crowd
|
./$NODE/.host/.scripts/20-crowd
|
||||||
@@ -128,10 +178,12 @@ Run the staged initialization scripts in order:
|
|||||||
Define the data tiers and secure the environment by creating non-root users for containerized services.
|
Define the data tiers and secure the environment by creating non-root users for containerized services.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# As root:
|
||||||
# Create (or mount) storage directories
|
# Create (or mount) storage directories
|
||||||
sudo mkdir -p /srv/com-ermnvldmr-root-$NODE-{tier1,tier2,tier3}
|
mkdir -p /srv/com-ermnvldmr-root-$NODE-{tier1,tier2,tier3}
|
||||||
|
|
||||||
# Setup tiers and non-root users
|
# Setup tiers and non-root users
|
||||||
|
cd $REPO_DIR
|
||||||
sudo -u adam .scripts/ops/setup-tiers $NODE \
|
sudo -u adam .scripts/ops/setup-tiers $NODE \
|
||||||
/srv/com-ermnvldmr-root-$NODE-tier1 \
|
/srv/com-ermnvldmr-root-$NODE-tier1 \
|
||||||
/srv/com-ermnvldmr-root-$NODE-tier2 \
|
/srv/com-ermnvldmr-root-$NODE-tier2 \
|
||||||
|
|||||||
@@ -0,0 +1,202 @@
|
|||||||
|
---
|
||||||
|
title: 'Начальная настройка хоста'
|
||||||
|
description: 'Настройка чистого хоста Debian с нуля.'
|
||||||
|
weight: 1
|
||||||
|
---
|
||||||
|
|
||||||
|
Защищенная настройка чистого хоста Debian от нуля до развертывания.
|
||||||
|
|
||||||
|
## Процедура настройки
|
||||||
|
|
||||||
|
{{% steps %}}
|
||||||
|
|
||||||
|
### Основные пакеты
|
||||||
|
|
||||||
|
Сначала установите `sudo` и `docker-ce`. Это необходимо, так как последующая настройка пользователя опирается на группу `docker` и конфигурацию `sudo`.
|
||||||
|
|
||||||
|
**Установка Sudo**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# От имени root:
|
||||||
|
apt update && apt install sudo -y
|
||||||
|
```
|
||||||
|
|
||||||
|
**Установка Docker**
|
||||||
|
|
||||||
|
Следуйте [официальному руководству по установке Docker для Debian](https://docs.docker.com/engine/install/debian/), чтобы установить последнюю версию Docker Engine.
|
||||||
|
|
||||||
|
### Системный пользователь и привилегии
|
||||||
|
|
||||||
|
Пользователь `adam` выполняет все административные задачи. Аутентификация по SSH-ключу и беспарольный `sudo` через группу `wheel` минимизируют трение при сохранении безопасности.
|
||||||
|
|
||||||
|
**Создание администратора**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# От имени root:
|
||||||
|
# Создать пользователя с оболочкой bash
|
||||||
|
useradd -m -s /bin/bash adam
|
||||||
|
|
||||||
|
# Создать группу wheel (общепринято для единообразия между дистрибутивами)
|
||||||
|
groupadd wheel
|
||||||
|
|
||||||
|
# Создать модульный файл sudoers
|
||||||
|
# Это позволяет членам группы 'wheel' запускать sudo без пароля
|
||||||
|
echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/99-root-ermnvldmr
|
||||||
|
|
||||||
|
# Проверить синтаксис
|
||||||
|
visudo -c -f /etc/sudoers.d/99-root-ermnvldmr
|
||||||
|
|
||||||
|
# Добавить adam в необходимые группы
|
||||||
|
usermod -aG wheel,docker adam
|
||||||
|
```
|
||||||
|
|
||||||
|
### Настройка Swap
|
||||||
|
|
||||||
|
Настройте файл подкачки (swap), чтобы обеспечить стабильность системы во время операций, требующих большого объема памяти.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# От имени root:
|
||||||
|
# Создать файл подкачки размером 2 ГБ (измените размер при необходимости)
|
||||||
|
fallocate -l 2G /swap
|
||||||
|
chmod 600 /swap
|
||||||
|
mkswap /swap
|
||||||
|
swapon /swap
|
||||||
|
|
||||||
|
# Сделать его постоянным
|
||||||
|
echo '/swap none swap sw 0 0' >> /etc/fstab
|
||||||
|
```
|
||||||
|
|
||||||
|
### SSH Доступ и Усиление
|
||||||
|
|
||||||
|
Пароли отключены. Доступ осуществляется строго по SSH-ключам.
|
||||||
|
|
||||||
|
**Авторизация ключа оператора**
|
||||||
|
|
||||||
|
Импортируйте ваш локальный публичный ключ для пользователя `adam`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# От имени root:
|
||||||
|
# Настроить директории
|
||||||
|
mkdir -p /home/adam/.ssh
|
||||||
|
chmod 700 /home/adam/.ssh
|
||||||
|
|
||||||
|
# Добавьте свой публичный ключ (Замените [PASTE_PUB_KEY_HERE])
|
||||||
|
echo "[PASTE_PUB_KEY_HERE]" > /home/adam/.ssh/authorized_keys
|
||||||
|
chmod 600 /home/adam/.ssh/authorized_keys
|
||||||
|
chown -R adam:adam /home/adam/.ssh
|
||||||
|
```
|
||||||
|
|
||||||
|
**Доступ со стороны оператора**
|
||||||
|
|
||||||
|
Настройте вашу локальную машину для удобного доступа к хосту.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# ~/.ssh/config на стороне оператора
|
||||||
|
Host daedalus.root.ermnvldmr.com
|
||||||
|
Port 2222
|
||||||
|
User adam
|
||||||
|
IdentityFile ~/.ssh/adam_root_ermnvldmr_com_ed25519
|
||||||
|
```
|
||||||
|
|
||||||
|
**Усиление демона SSH**
|
||||||
|
|
||||||
|
Измените конфигурацию SSH, чтобы сменить порт по умолчанию и отключить вход по паролю.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# От имени root:
|
||||||
|
# Создать выделенный файл конфигурации
|
||||||
|
cat <<EOF > /etc/ssh/sshd_config.d/99-root-ermnvldmr.conf
|
||||||
|
Port 2222
|
||||||
|
PasswordAuthentication no
|
||||||
|
PermitEmptyPasswords no
|
||||||
|
AllowUsers adam
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Проверить синтаксис перед перезапуском, чтобы избежать блокировки
|
||||||
|
sshd -t && systemctl restart ssh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Доступ к GitHub (Deploy Key)
|
||||||
|
|
||||||
|
Хосту требуется собственная идентификация для загрузки обновлений из репозитория GitHub.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# От имени root:
|
||||||
|
# Сгенерировать специфичный для хоста SSH-ключ (без парольной фразы для автоматизации)
|
||||||
|
sudo -u adam ssh-keygen -t ed25519 -f /home/adam/.ssh/github_ed25519 -N ""
|
||||||
|
|
||||||
|
# Настроить SSH для использования этого ключа для GitHub
|
||||||
|
cat <<EOF | sudo -u adam tee /home/adam/.ssh/config
|
||||||
|
Host github.com
|
||||||
|
AddKeysToAgent yes
|
||||||
|
IdentityFile ~/.ssh/github_ed25519
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Отобразить публичный ключ для добавления в GitHub (Settings > Deploy Keys)
|
||||||
|
cat /home/adam/.ssh/github_ed25519.pub
|
||||||
|
```
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
> Добавьте вывод выше в [GitHub: Repository Deploy Keys](https://github.com/deytenit/root.ermnvldmr.com/settings/keys) с правами **read access**.
|
||||||
|
|
||||||
|
### Развертывание репозитория
|
||||||
|
|
||||||
|
Клонируйте инфраструктурный репозиторий и инициализируйте узел.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# От имени root:
|
||||||
|
# Настроить директорию сервиса
|
||||||
|
export REPO_DIR="/srv/root.ermnvldmr.com"
|
||||||
|
mkdir -p $REPO_DIR
|
||||||
|
chown adam:adam $REPO_DIR
|
||||||
|
|
||||||
|
# Клонировать от имени пользователя adam
|
||||||
|
sudo -u adam git clone git@github.com:deytenit/root.ermnvldmr.com.git $REPO_DIR
|
||||||
|
|
||||||
|
# Инициализировать узел (Установите имя вашего узла, например, daedalus)
|
||||||
|
export NODE="daedalus"
|
||||||
|
cd $REPO_DIR
|
||||||
|
sudo -u adam ./init.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
**Специфичная для узла конфигурация**
|
||||||
|
|
||||||
|
Запустите скрипты инициализации по порядку:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# От имени root:
|
||||||
|
# Выполните последовательность для вашего конкретного узла
|
||||||
|
cd $REPO_DIR
|
||||||
|
./$NODE/.host/.scripts/00-base
|
||||||
|
./$NODE/.host/.scripts/10-ufw
|
||||||
|
./$NODE/.host/.scripts/20-crowd
|
||||||
|
./$NODE/.host/.scripts/30-cron
|
||||||
|
```
|
||||||
|
|
||||||
|
### Хранение и усиление безопасности
|
||||||
|
|
||||||
|
Определите уровни данных (tiers) и защитите среду, создав непривилегированных пользователей для контейнеризированных сервисов.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# От имени root:
|
||||||
|
# Создать (или примонтировать) директории хранилища
|
||||||
|
mkdir -p /srv/com-ermnvldmr-root-$NODE-{tier1,tier2,tier3}
|
||||||
|
|
||||||
|
# Настроить уровни и непривилегированных пользователей
|
||||||
|
cd $REPO_DIR
|
||||||
|
sudo -u adam .scripts/ops/setup-tiers $NODE
|
||||||
|
/srv/com-ermnvldmr-root-$NODE-tier1
|
||||||
|
/srv/com-ermnvldmr-root-$NODE-tier2
|
||||||
|
/srv/com-ermnvldmr-root-$NODE-tier3
|
||||||
|
|
||||||
|
sudo -u adam .scripts/ops/setup-noroot-users $NODE
|
||||||
|
```
|
||||||
|
|
||||||
|
{{% /steps %}}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**См. также:**
|
||||||
|
|
||||||
|
- [Doc: Docker - Install on Debian](https://docs.docker.com/engine/install/debian/)
|
||||||
|
- [GitHub: root.ermnvldmr.com](https://github.com/deytenit/root.ermnvldmr.com)
|
||||||
Reference in new issue
Block a user