技能 编程开发 Fly.io 安装与身份认证配置

Fly.io 安装与身份认证配置

v20260423
flyio-install-auth
本指南详细介绍了如何安装 flyctl 命令行工具,并配置 Fly.io 平台的身份认证。它涵盖了交互式登录和使用API令牌(包括用户、部署和组织令牌)的多种认证方法,是进行边缘计算部署和自动化 CI/CD 流程的关键步骤。
获取技能
154 次下载
概览

Fly.io Install & Auth

Overview

Install flyctl CLI and configure authentication for Fly.io edge compute platform. Two auth methods: interactive login (opens browser) and API tokens (CI/CD and Machines API). The Machines API base URL is https://api.machines.dev.

Prerequisites

  • Fly.io account at fly.io
  • macOS, Linux, or WSL2

Instructions

Step 1: Install flyctl

# macOS / Linux
curl -L https://fly.io/install.sh | sh

# Or via Homebrew
brew install flyctl

# Verify
fly version

Step 2: Authenticate

# Interactive login (opens browser)
fly auth login

# Or with token (CI/CD)
fly auth token  # Get current token
export FLY_API_TOKEN="fo1_your_token_here"

# Verify auth
fly auth whoami

Step 3: Create API Token for Machines API

# Create deploy token (scoped to an app)
fly tokens create deploy -a my-app

# Create org-level token
fly tokens create org

# Use with Machines API
curl -s -H "Authorization: Bearer $FLY_API_TOKEN" \
  https://api.machines.dev/v1/apps | jq '.[].name'

Step 4: Verify Machines API Access

const FLY_API = 'https://api.machines.dev';

async function verifyFlyAccess() {
  const res = await fetch(`${FLY_API}/v1/apps`, {
    headers: { 'Authorization': `Bearer ${process.env.FLY_API_TOKEN}` },
  });
  const apps = await res.json();
  console.log(`Connected. Found ${apps.length} apps.`);
  apps.forEach((app: any) => console.log(`  ${app.name} (${app.organization.slug})`));
}

Token Types

Token Type Scope Lifetime Use Case
User token All orgs/apps Until revoked Development, personal
Deploy token Single app Until revoked CI/CD per app
Org token All apps in org Until revoked Org-wide automation
Machines token API access Until revoked Machines API calls

Error Handling

Error Cause Solution
Error: not authenticated No token set Run fly auth login or set FLY_API_TOKEN
401 Unauthorized Invalid/expired token Regenerate with fly tokens create
Could not find app Wrong app name Check with fly apps list
flyctl not found CLI not installed Run install script above

Resources

Next Steps

After auth, proceed to flyio-hello-world for your first deployment.

信息
Category 编程开发
Name flyio-install-auth
版本 v20260423
大小 3.05KB
更新时间 2026-04-26
语言