身份验证#
tgs 通过 MTProto 协议使用您的真实用户账户连接到 Telegram。每个配置文件只需认证一次——会话保存在本地,后续命令自动复用。
快速开始#
默认方式是从已有的 Telegram Desktop 客户端导入会话:
tgs login或选择其他登录方式:
tgs login --type code # Phone number + SMS/Telegram code
tgs login --type qr # Scan QR code from another device登录方式#
Desktop 导入(默认)#
从 Telegram Desktop 导入现有会话。tgs 会自动检测 macOS、Linux 和 Windows 上的 tdata 目录。
# Auto-detect Telegram Desktop data
tgs login
# Custom tdata path
tgs login --desktop-dir /path/to/tdata
# Passcode-protected Telegram Desktop client
tgs login --passcode SECRET无需输入手机号或验证码——会话直接传输。
手机验证码#
通过手机号进行交互式登录,支持两步验证(云密码)。
# Interactive — prompts for phone and code
tgs login --type code
# Provide phone upfront
tgs login --type code --phone +1234567890tgs 会提示输入 Telegram 发送的验证码。如果启用了两步验证,请通过 --password 标志传入云密码——tgs 不会交互式提示输入。
非交互式登录(适用于 AI 代理)#
code 方式支持完全非交互的两步登录流程。这是 AI 代理和自动化工具的推荐方式。
# Step 1: request the code
tgs login --type code --phone +1234567890
# → {"status":"code_sent","profile":"default"}
# Step 2: complete login with the received code
tgs login --type code --phone +1234567890 --code 12345
# → {"status":"logged_in","user":{...}}
# With 2FA
tgs login --type code --phone +1234567890 --code 12345 --password mysecret二维码#
在终端中显示二维码,使用其他设备上的 Telegram 应用扫描即可。
tgs login --type qr扫描后 tgs 会自动完成认证。二维码登录不支持启用了两步验证的账户——对于这类账户请使用 code 方式并配合 --password。
登录到指定配置文件#
使用 --profile 可登录到指定的命名配置文件。如果配置文件不存在,会自动创建。
tgs login --profile work
tgs login --type code --profile personal多账户设置详见配置文件。
验证登录#
登录后,确认当前活跃账户:
tgs whoami退出登录#
tgs logout # logout current profile
tgs logout --profile work # logout specific profile退出登录会在 Telegram 服务器上撤销会话,并清除本地会话数据。
完整参数参考#
详见 tgs login 和 tgs logout 的完整参数说明。