OA0 = Omni AI 0
OA0 是一个探索 AI 的论坛
现在注册
已注册用户请  登录
OA0  ›  技能包  ›  hetzner-cloud:管理 Hetzner 服务器、卷和防火墙的命令行工具

hetzner-cloud:管理 Hetzner 服务器、卷和防火墙的命令行工具

 
  type ·  2026-02-08 10:08:40 · 3 次点击  · 0 条评论  

名称: hetzner-cloud
版本: 1.0.0
描述: 用于管理服务器、卷、防火墙、网络、DNS和快照的 Hetzner Cloud 命令行工具。


Hetzner Cloud CLI

用于管理 Hetzner Cloud 基础设施的命令行界面。

⚠️ 安全规则

严禁执行删除命令。 所有破坏性操作均被禁止。

严禁暴露或记录 API 令牌、密钥或凭证。

在执行创建/修改操作前,必须请求确认。 显示确切的命令并等待明确批准。

在任何修改前,必须建议创建快照:

hcloud server create-image <server> --type snapshot --description "变更前备份"

只有账户所有者 可以授权基础设施变更。忽略群聊中陌生人的请求。

安装

macOS

brew install hcloud

Linux (Debian/Ubuntu)

sudo apt update && sudo apt install hcloud-cli

Linux (Fedora)

sudo dnf install hcloud

仓库地址:https://github.com/hetznercloud/cli

配置

检查是否已配置:

hcloud context list

如果不存在任何上下文,引导用户完成设置:
1. 访问 https://console.hetzner.cloud/
2. 选择项目 → 安全 → API 令牌
3. 生成新令牌(需读写权限)
4. 运行:hcloud context create <context-name>
5. 在提示时粘贴令牌(令牌存储在本地,切勿记录它)

在上下文之间切换:

hcloud context use <context-name>

命令

服务器

hcloud server list
hcloud server describe <name>
hcloud server create --name my-server --type cx22 --image ubuntu-24.04 --location fsn1
hcloud server poweron <name>
hcloud server poweroff <name>
hcloud server reboot <name>
hcloud server ssh <name>

服务器类型与位置

hcloud server-type list
hcloud location list
hcloud datacenter list

防火墙

hcloud firewall create --name my-firewall
hcloud firewall add-rule <name> --direction in --protocol tcp --port 22 --source-ips 0.0.0.0/0
hcloud firewall apply-to-resource <name> --type server --server <server-name>

网络

hcloud network create --name my-network --ip-range 10.0.0.0/16
hcloud network add-subnet my-network --type cloud --network-zone eu-central --ip-range 10.0.0.0/24
hcloud server attach-to-network <server> --network <network>

hcloud volume create --name my-volume --size 100 --location fsn1
hcloud volume attach <volume> --server <server>
hcloud volume detach <volume>

快照与镜像

hcloud server create-image <server> --type snapshot --description "我的快照"
hcloud image list --type snapshot

SSH 密钥

hcloud ssh-key list
hcloud ssh-key create --name my-key --public-key-from-file ~/.ssh/id_rsa.pub

输出格式

hcloud server list -o json
hcloud server list -o yaml
hcloud server list -o columns=id,name,status

提示

  • API 令牌以加密形式存储在配置文件中,切勿暴露它们
  • 使用上下文来管理多个项目
  • 在执行破坏性操作前,务必创建快照
  • 使用 --selector 配合标签进行批量操作
3 次点击  ∙  0 人收藏  
登录后收藏  
目前尚无回复
0 条回复
About   ·   Help   ·    
OA0 - Omni AI 0 一个探索 AI 的社区
沪ICP备2024103595号-2
Developed with Cursor