选择连接方法
当您从Atlas CLI连接到现有Atlas帐户时,可以使用 atlas auth login 命令的以下选项之一进行身份验证:
选项 | 身份验证方法 | 用例(Use Case) |
|---|---|---|
| Atlas 登录凭证和身份验证令牌 | 最适合非编程使用 |
| 服务帐户 | 最适合通过服务帐号以编程方式使用 |
| API 密钥 | 最适合通过API密钥以编程方式使用 |
重要
对于 Atlas CLI 在 1.47 之前的版本,API 密钥以明文形式存储在 Atlas CLI 配置文件中。API 密钥就像密码一样。确保以适当方式保护配置文件。Atlas CLI 1.47+ 尝试安全地存储凭证。
要创建新的 Atlas 帐户或启用没有任何群集的现有帐户,请参阅开始使用 Atlas。
选择下方的使用案例,以了解有关可用连接选项的更多信息:
使用 atlas auth login 命令并使用 UserAccount 选项,并使用您的 Atlas 登录凭证和一次性身份验证令牌进行身份验证。UserAccount 选项需要手动登录并验证身份验证令牌,该令牌的有效期为 12 小时。使用 UserAccount 选项连接时,API 密钥是可选的。
使用 UserAccount 选项运行atlas auth login 后,您可以:
Connect with minimum required settings and specify the
--projectIdand--orgIdflags with each command. This is the quickest way to get started for first-time login.
当您运行带有 ServiceAccounts 选项的 atlas auth login 命令时,Atlas CLI会提示您提供客户端ID和密钥。ServiceAccounts 选项非常适合编程使用,因为它允许您自动执行和管理MongoDB资源。服务帐户(也称为 OAuth 应用程序)允许通过指定的安全客户端ID和密钥进行编程访问权限。此方法非常适合编写用例脚本和持续集成或交付工作流程。
注意
这个进程是交互式的。对于编程身份验证,请在使用 {atlas-cli+} 之前设立MONGODB_ATLAS_CLIENT_ID 和 MONGODB_ATLAS_CLIENT_SECRET 环境变量。要学习有关所有支持的环境变量的更多信息,请参阅Atlas CLI环境变量。
您必须配置 API 密钥才能使用此命令进行身份验证。
运行带有 APIKeys 选项的 atlas auth login 命令时,Atlas CLI 会提示您提供 API 密钥,并自动创建一个存储 API 密钥的配置文件。APIKeys 选项适合以编程方式使用,因为它不需要手动登录或令牌验证。
使用带有 APIKeys 选项的 atlas auth login 命令进行连接时,您可以:
Connect with minimum required settings and specify the
--projectIdand--orgIdflags with each command. This is the quickest way to get started for first-time login.
使用最少必要设置进行连接
选择一个使用案例,按照步骤以所需的最低设置从 Atlas CLI 进行连接。
满足先决条件
Add your host's IP address to the IP access list.
If you authenticate with your Atlas user credentials and your organization's owners enable IP access list for the Atlas UI for an organization, your IP address must be added to the IP access list to run commands in this organization. To learn more, see Require IP Access List for the Atlas UI.
在开始之前,请确保您拥有:
一个活跃的Atlas组织。
A Service Account created and configured. To learn more, see Grant Programmatic Access to an Organization.
服务帐户的客户端ID和密钥。
按照以下步骤操作
选择一个使用案例并按照步骤从 Atlas CLI 进行快速连接。
使用--projectId 和--orgId 标志发出命令。
当您在 Atlas CLI 会话期间运行 Atlas CLI 命令时,请使用 --projectId 和 --orgId 标志指定您的项目 ID 和组织 ID。
例子
atlas alerts list --projectId 60b3c81153cf986293e2608b
使用--projectId 和--orgId 标志发出命令。
当您在 Atlas CLI 会话期间运行 Atlas CLI 命令时,请使用 --projectId 和 --orgId 标志指定您的项目 ID 和组织 ID。
例子
atlas alerts list --projectId 60b3c81153cf986293e2608b
使用--projectId 和--orgId 标志发出命令。
当您在 Atlas CLI 会话期间运行 Atlas CLI 命令时,请使用 --projectId 和 --orgId 标志指定您的项目 ID 和组织 ID。
例子
atlas alerts list --projectId 60b3c81153cf986293e2608b
采取后续步骤
开始使用 Atlas CLI 命令。
要通过修改默认配置文件或创建不同的配置文件来保存连接设置,请参阅保存连接设置。