hetzner-server by connorads/dotfiles
npx skills add https://github.com/connorads/dotfiles --skill hetzner-server使用 hcloud CLI 创建和管理 Hetzner Cloud 服务器。
hcloud CLI(通过 mise:hcloud = "latest")hcloud context create <name>在服务器创建时应用的可重用防火墙配置文件。防火墙可以在运行中的服务器上更换——使用 apply-to-resource / remove-from-resource。
| 防火墙 | 规则 | 用例 |
|---|
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
ts-ssh | UDP 41641 (Tailscale) + TCP 22 (SSH) | 开发机——初始设置,在 tsonlyssh 后更换为 ts-only |
ts-only | UDP 41641 (Tailscale) | 仅限 Tailscale 访问,无公共端口 |
ts-web | UDP 41641 (Tailscale) + TCP 80,443 (HTTP/S) | 接受公共网络流量的服务器 |
hcloud firewall remove-from-resource ts-ssh --type server --server dev
hcloud firewall apply-to-resource ts-only --type server --server dev
# 优先选择 ARM(性价比最高)
hcloud server create \
--name dev \
--type cax21 \
--image ubuntu-24.04 \
--location nbg1 \
--ssh-key connorads \
--ssh-key connor@penguin \
--firewall ts-ssh
# x86 备选方案
hcloud server create \
--name dev \
--type cpx21 \
--image ubuntu-24.04 \
--location nbg1 \
--ssh-key connorads \
--ssh-key connor@penguin \
--firewall ts-ssh
# 仅 IPv6(每月节省约 $0.60 的 IPv4 费用)
hcloud server create \
--name dev \
--type cax21 \
--image ubuntu-24.04 \
--location nbg1 \
--ssh-key connorads \
--ssh-key connor@penguin \
--firewall ts-ssh \
--without-ipv4
# 使用 heredoc - 进程替换 <(echo '...') 会错误地转义 shebang
hcloud server create \
--name dev \
--type cax21 \
--image ubuntu-24.04 \
--location nbg1 \
--ssh-key connorads \
--ssh-key connor@penguin \
--firewall ts-ssh \
--user-data-from-file - <<'EOF'
#!/bin/bash
curl -fsSL https://raw.githubusercontent.com/connorads/dotfiles/master/install.sh | bash
EOF
点文件安装大约需要 5 分钟。要监控进度:
# 快速状态检查
ssh connor@$(hcloud server ip dev) "cloud-init status"
# 查看最近的安装日志
ssh connor@$(hcloud server ip dev) "sudo journalctl -u cloud-final -n 50 --no-pager"
# 实时跟踪安装过程
ssh connor@$(hcloud server ip dev) "sudo journalctl -u cloud-final -f"
# 检查工具是否已安装
ssh connor@$(hcloud server ip dev) "which zsh mise && echo \$SHELL"
Ubuntu 云镜像默认不包含交换空间。在创建时通过 cloud-init 添加交换空间:
# 创建带有 16GB 交换空间的服务器(16GB RAM 服务器的 1:1 比例)
hcloud server create \
--name dev \
--type cax33 \
--image ubuntu-24.04 \
--location nbg1 \
--ssh-key connorads \
--ssh-key connor@penguin \
--firewall ts-ssh \
--user-data-from-file - <<'EOF'
#cloud-config
swap:
filename: /swapfile
size: 16G
maxsize: 16G
EOF
推荐的交换空间大小:
向现有服务器添加交换空间:
# 创建 16GB 交换文件
ssh connor@$(hcloud server ip dev) "sudo fallocate -l 16G /swapfile && \
sudo chmod 600 /swapfile && \
sudo mkswap /swapfile && \
sudo swapon /swapfile && \
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab"
# 验证交换空间已激活
ssh connor@$(hcloud server ip dev) "free -h"
# 列出服务器
hcloud server list
# 获取服务器 IP
hcloud server ip dev
# SSH 连接到服务器
ssh connor@$(hcloud server ip dev)
# 删除服务器
hcloud server delete dev
# 电源操作
hcloud server poweroff dev
hcloud server poweron dev
hcloud server reboot dev
# 重建(重装操作系统,保留 IP)
hcloud server rebuild dev --image ubuntu-24.04
欧盟区域的价格(美元)(美国区域价格高约 20%):
| 类型 | 架构 | vCPU | 内存 | 磁盘 | 约美元/月 |
|---|---|---|---|---|---|
| cax11 | ARM | 2 | 4GB | 40GB | $4.50 |
| cax21 | ARM | 4 | 8GB | 80GB | $8 |
| cax31 | ARM | 8 | 16GB | 160GB | $16 |
| cpx21 | x86 | 3 | 4GB | 80GB | $9 |
| cpx31 | x86 | 4 | 8GB | 160GB | $18 |
完整列表:hcloud server-type list
| ID | 城市 | 国家 |
|---|---|---|
| fsn1 | 法尔肯施泰因 | 德国 |
| nbg1 | 纽伦堡 | 德国 |
| hel1 | 赫尔辛基 | 芬兰 |
| ash | 阿什本 | 美国 |
| hil | 希尔斯伯勒 | 美国 |
| sin | 新加坡 | 新加坡 |
# 列出密钥
hcloud ssh-key list
# 添加密钥
hcloud ssh-key create --name mykey --public-key-from-file ~/.ssh/id_ed25519.pub
# 列出系统镜像
hcloud image list --type system
# ARM 镜像
hcloud image list --type system --architecture arm
使用启用了代理转发的 <name>-agent SSH 主机来克隆私有仓库,无需将密钥复制到服务器。如果遇到主机密钥错误,请先添加 GitHub 的主机密钥。
# 仅首次需要:添加 GitHub 的主机密钥
ssh dev "ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null"
# 确认转发的代理可见
ssh dev-agent "ssh-add -l"
# 使用代理转发进行克隆(使用 -agent 后缀)
ssh dev-agent "mkdir -p ~/git && cd ~/git && git clone git@github.com:you/repo.git"
# 克隆特定分支
ssh dev-agent "mkdir -p ~/git && cd ~/git && git clone git@github.com:you/repo.git && cd repo && git checkout branch-name"
# 使用代理转发进行推送/拉取
ssh dev-agent "cd repo && git push"
对于交互式会话(例如,lazygit):
ssh dev-agent
# 然后在服务器上:git clone/push/pull 可以使用转发的代理
创建服务器后,务必清除该 IP 的任何旧主机密钥(Hetzner 会重用 IP):
ssh-keygen -R $(hcloud server ip dev) 2>/dev/null
ssh-keyscan $(hcloud server ip dev) >> ~/.ssh/known_hosts 2>/dev/null
然后生成/更新 SSH 配置条目:
hcssh # 使用所有 Hetzner 服务器更新 ~/.ssh/config
hcssh --dry-run # 预览而不写入
这会在托管块(# BEGIN/END hetzner-managed)内为每个服务器创建两个 Host 条目:
<name> — 无代理转发(对 AI 代理安全)<name>-agent — 带有代理转发(用于向 GitHub 推送/拉取)创建/删除服务器后再次运行 hcssh 以保持 SSH 配置同步。这使得 VS Code Remote-SSH 可以在下拉列表中显示服务器。
在 ts up 并确认通过 Tailscale 的 SSH 可以工作(ts ssh connor@dev)之后,在服务器上运行 tsonlyssh 以从 UFW 中移除公共端口 22。这使得 SSH 只能通过 Tailscale 接口访问。
备用方案:如果被锁定,使用 Hetzner Cloud Console VNC。
connor、安装 Nix、home-manager 和 mise 工具每周安装次数
112
仓库
GitHub 星标数
8
首次出现
2026年1月24日
安全审计
安装在
opencode107
gemini-cli106
codex106
github-copilot104
claude-code101
amp98
Create and manage Hetzner Cloud servers using the hcloud CLI.
hcloud CLI installed (via mise: hcloud = "latest")hcloud context create <name> with API token from https://console.hetzner.cloudReusable firewall profiles applied at server creation. Firewalls can be swapped on running servers — use apply-to-resource / remove-from-resource.
| Firewall | Rules | Use case |
|---|---|---|
ts-ssh | UDP 41641 (Tailscale) + TCP 22 (SSH) | Dev boxes — initial setup, swap to ts-only after tsonlyssh |
ts-only | UDP 41641 (Tailscale) | Tailscale-only access, no public ports |
ts-web | UDP 41641 (Tailscale) + TCP 80,443 (HTTP/S) | Servers accepting public web traffic |
hcloud firewall remove-from-resource ts-ssh --type server --server dev
hcloud firewall apply-to-resource ts-only --type server --server dev
# Prefer ARM (best value)
hcloud server create \
--name dev \
--type cax21 \
--image ubuntu-24.04 \
--location nbg1 \
--ssh-key connorads \
--ssh-key connor@penguin \
--firewall ts-ssh
# x86 fallback
hcloud server create \
--name dev \
--type cpx21 \
--image ubuntu-24.04 \
--location nbg1 \
--ssh-key connorads \
--ssh-key connor@penguin \
--firewall ts-ssh
# IPv6-only (saves ~$0.60/month on IPv4)
hcloud server create \
--name dev \
--type cax21 \
--image ubuntu-24.04 \
--location nbg1 \
--ssh-key connorads \
--ssh-key connor@penguin \
--firewall ts-ssh \
--without-ipv4
# Use heredoc - process substitution <(echo '...') escapes the shebang incorrectly
hcloud server create \
--name dev \
--type cax21 \
--image ubuntu-24.04 \
--location nbg1 \
--ssh-key connorads \
--ssh-key connor@penguin \
--firewall ts-ssh \
--user-data-from-file - <<'EOF'
#!/bin/bash
curl -fsSL https://raw.githubusercontent.com/connorads/dotfiles/master/install.sh | bash
EOF
The dotfiles installation takes ~5 minutes. To monitor progress:
# Quick status check
ssh connor@$(hcloud server ip dev) "cloud-init status"
# View recent installation logs
ssh connor@$(hcloud server ip dev) "sudo journalctl -u cloud-final -n 50 --no-pager"
# Follow installation in real-time
ssh connor@$(hcloud server ip dev) "sudo journalctl -u cloud-final -f"
# Check if tools are installed
ssh connor@$(hcloud server ip dev) "which zsh mise && echo \$SHELL"
Ubuntu cloud images don't include swap by default. Add swap via cloud-init at creation:
# Create server with 16GB swap (1:1 ratio for 16GB RAM server)
hcloud server create \
--name dev \
--type cax33 \
--image ubuntu-24.04 \
--location nbg1 \
--ssh-key connorads \
--ssh-key connor@penguin \
--firewall ts-ssh \
--user-data-from-file - <<'EOF'
#cloud-config
swap:
filename: /swapfile
size: 16G
maxsize: 16G
EOF
Recommended swap sizes:
Add swap to existing server:
# Create 16GB swap file
ssh connor@$(hcloud server ip dev) "sudo fallocate -l 16G /swapfile && \
sudo chmod 600 /swapfile && \
sudo mkswap /swapfile && \
sudo swapon /swapfile && \
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab"
# Verify swap is active
ssh connor@$(hcloud server ip dev) "free -h"
# List servers
hcloud server list
# Get server IP
hcloud server ip dev
# SSH to server
ssh connor@$(hcloud server ip dev)
# Delete server
hcloud server delete dev
# Power operations
hcloud server poweroff dev
hcloud server poweron dev
hcloud server reboot dev
# Rebuild (reinstall OS, keeps IP)
hcloud server rebuild dev --image ubuntu-24.04
Prices in USD for EU regions (US regions ~20% higher):
| Type | Arch | vCPU | RAM | Disk | ~USD/mo |
|---|---|---|---|---|---|
| cax11 | ARM | 2 | 4GB | 40GB | $4.50 |
| cax21 | ARM | 4 | 8GB | 80GB | $8 |
| cax31 | ARM | 8 | 16GB | 160GB | $16 |
| cpx21 | x86 | 3 | 4GB | 80GB | $9 |
| cpx31 | x86 | 4 | 8GB | 160GB |
Full list: hcloud server-type list
| ID | City | Country |
|---|---|---|
| fsn1 | Falkenstein | DE |
| nbg1 | Nuremberg | DE |
| hel1 | Helsinki | FI |
| ash | Ashburn | US |
| hil | Hillsboro | US |
| sin | Singapore | SG |
# List keys
hcloud ssh-key list
# Add a key
hcloud ssh-key create --name mykey --public-key-from-file ~/.ssh/id_ed25519.pub
# List system images
hcloud image list --type system
# ARM images
hcloud image list --type system --architecture arm
Use the <name>-agent SSH host (which has agent forwarding enabled) to clone private repos without copying keys to the server. If you hit host key errors, add GitHub's host key first.
# First time only: add GitHub's host key
ssh dev "ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null"
# Confirm forwarded agent is visible
ssh dev-agent "ssh-add -l"
# Clone with agent forwarding (use -agent suffix)
ssh dev-agent "mkdir -p ~/git && cd ~/git && git clone git@github.com:you/repo.git"
# Clone specific branch
ssh dev-agent "mkdir -p ~/git && cd ~/git && git clone git@github.com:you/repo.git && cd repo && git checkout branch-name"
# Push/pull with agent forwarding
ssh dev-agent "cd repo && git push"
For interactive sessions (e.g., lazygit):
ssh dev-agent
# Then on server: git clone/push/pull works with forwarded agent
After creating a server, always clear any old host keys for that IP (Hetzner reuses IPs):
ssh-keygen -R $(hcloud server ip dev) 2>/dev/null
ssh-keyscan $(hcloud server ip dev) >> ~/.ssh/known_hosts 2>/dev/null
Then generate/update SSH config entries:
hcssh # update ~/.ssh/config with all Hetzner servers
hcssh --dry-run # preview without writing
This creates two Host entries per server inside a managed block (# BEGIN/END hetzner-managed):
<name> — no agent forwarding (safe for AI agents)<name>-agent — with agent forwarding (for git push/pull to GitHub)Run hcssh again after creating/deleting servers to keep SSH config in sync. This enables VS Code Remote-SSH to show the server in the dropdown.
After ts up and confirming SSH works via Tailscale (ts ssh connor@dev), run tsonlyssh on the server to remove public port 22 from UFW. This leaves SSH accessible only via the Tailscale interface.
Fallback: Hetzner Cloud Console VNC if locked out.
connor, installing Nix, home-manager, and mise toolsWeekly Installs
112
Repository
GitHub Stars
8
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketFailSnykFail
Installed on
opencode107
gemini-cli106
codex106
github-copilot104
claude-code101
amp98
Android无障碍功能检查清单:内容描述、触摸目标、色彩对比度、焦点语义完整指南
202 周安装
Magento 2 Hyvä 主题列表工具 - 快速发现项目中的所有 Hyvä 主题路径
213 周安装
floor-plan:基于Drawio的Markdown平面图与布局生成器,快速创建家居/办公室设计图
205 周安装
LinkedIn广告健康度审计工具 - 25项检查清单,优化B2B广告效果与ROI
202 周安装
oh-my-claudecode技能管理CLI教程:创建、列表、删除技能命令详解
206 周安装
Hyvä子主题创建工具 - 快速生成Magento 2 Hyvä主题目录与配置文件
209 周安装
| $18 |