الأكاديمية ← أدلة تطبيقيةتوثيق رسمي · إرشاد عربي

إتمام OAuth على خادم بعيد عبر SSH

OAuth over SSH / Remote Hosts

متوسط7 دقائق قراءةالدرس 27سؤالان✓ 2026-08-18
قبل أن تقرأ

ما هذه الصفحة، وماذا تحتوي.

الأسرار والمفاتيح: كلمات السر ومفاتيح الخدمات التي يحتاجها Hermes ليدخل إلى حساباتك. تُحفظ في مكان واحد محمي، فلا تظهر في المحادثات ولا في الملفات التي تشاركها. ستستعمل هنا hermes auth spotify، والقراءة نحو 7 دقائق. انتبه: لا تكتب مفتاحًا داخل محادثة ولا داخل ملف إعداد تشاركه. استعمل متغيرات البيئة أو مدير أسرار.

9أقسام
9أمثلة برمجية
1جداول
1أوامر
1,239كلمة من المصدر
الوصف الرسمي في سطر

How to complete browser-based OAuth (Spotify, MCP servers) when Hermes runs on a remote machine, container, or behind a jump box

ماذا ستستطيع بعدها

نتائج مأخوذة من هذه الصفحة، لا من قالب.

  • تعرف ما الأسرار والمفاتيح ولماذا قد تحتاجه.
  • تنفّذ hermes auth spotify وتفهم ما يحدث بعدها.
  • تقرأ الجدول وتأخذ منه السطر الذي يخصّك فقط.
ما ستقابله من أسماء

كما تظهر تمامًا داخل Hermes.

الأوامر
  • hermes auth spotify
خريطة الصفحة

انتقل مباشرة إلى ما تحتاجه.

  1. 01TL;DR
  2. 02Which Providers Need This
  3. 03MCP Servers
  4. 04Why the listener can't just bind 0.0.0.0
  5. 05Step-by-step: single SSH hop
  6. 06Step-by-step: through a jump box
  7. 07Mosh, tmux, ssh ControlMaster
  8. 08Troubleshooting
  9. 09See Also
الصفحة الرسمية كاملة

بلا اختصار أو حذف.

النص أدناه منقول من المصدر الرسمي بالإنجليزية حتى تبقى الأوامر والأسماء دقيقة كما هي. قبل كل قسم شرح عربي يوضّح ما بداخله.

Some Hermes providers — Spotify and remote MCP servers (Linear, Sentry, Atlassian, Asana, Figma, …) — use a loopback redirect OAuth flow. The auth server redirects your browser to http://127.0.0.1:<port>/callback so a tiny HTTP listener started by Hermes can grab the authorization code.

This works perfectly when Hermes and your browser are on the same machine. It breaks the moment they aren't: your laptop's browser tries to reach 127.0.0.1 on your laptop, but the listener is bound to 127.0.0.1 on the remote server.

The fix is a one-line SSH local-forward. For MCP servers on an interactive terminal, you can often paste the redirect URL back instead (no tunnel).

xAI Grok OAuth (xai-oauth) uses OAuth device code, not a loopback callback — open the printed verification URL in any browser and Hermes polls until approval. No SSH tunnel is required. See xAI Grok OAuth.

TL;DR

أوامر تكتبها في الطرفية. افهم ما يفعله الأمر قبل نسخه. الأوامر هنا: hermes auth spotify.

Shell8 أسطر
# On your local machine (laptop), in a separate terminal:
ssh -N -L 43827:127.0.0.1:43827 user@remote-host

# In your existing SSH session on the remote machine:
hermes auth spotify --no-browser
# → Hermes prints an authorize URL. Open it in a browser on your laptop.
# → Your browser redirects to 127.0.0.1:43827/callback, the tunnel forwards
#   the request to the remote listener, login completes.

Hermes prints the exact port it bound to on the Waiting for callback on ... line — copy it from there. Spotify defaults to port 43827.

Which Providers Need This

جدول مرجعي. لا تقرأه كله، ابحث عن السطر الذي يخصّك فقط.

ProviderLoopback portTunnel needed?
Spotify43827 (default)Yes, when Hermes is remote
MCP servers (auth: oauth)auto-picked per serverYes, when Hermes is remote (or paste redirect URL)
xai-oauth (Grok SuperGrok)n/aNo — device code flow
anthropic (Claude Pro/Max)n/aNo — paste-the-code flow
openai-codex (ChatGPT Plus/Pro)n/aNo — device code flow
minimax, nous-portaln/aNo — device code flow

If your provider isn't in the table, you don't need a tunnel.

MCP Servers

شرح للفكرة نفسها. اقرأه ببطء، فبقية الأقسام تبني عليه. تذكير: كلمات السر ومفاتيح الخدمات التي يحتاجها Hermes ليدخل إلى حساباتك.

Remote MCP servers (Linear, Sentry, Atlassian, Asana, Figma, etc.) use the same loopback redirect flow. Hermes auto-picks a free port per server and prints the authorize URL when the OAuth flow kicks off — either at startup (when a new server appears in mcp_servers:) or when you run hermes mcp login <server>.

You have two ways to complete it from a remote host:

Option 1 — paste the redirect URL back (no setup, works anywhere). On an interactive terminal, Hermes prompts you to paste the redirect URL alongside running the local listener. After approving in your browser, the redirect to http://127.0.0.1:<port>/callback will show a connection error — that's expected. Copy the full URL from the browser's address bar and paste it at the Hermes prompt:

Text8 أسطر
  MCP OAuth: authorization required.
  Open this URL in your browser:

    https://mcp.linear.app/authorize?response_type=code&...

  Or paste the redirect URL here (or the ?code=...&state=... portion) and press Enter:
> https://mcp.linear.app/callback?code=abc123&state=xyz
  Got authorization code from paste — completing flow.

A bare ?code=...&state=... query string is accepted too. This works for any MCP server with auth: oauth and requires no SSH config changes.

Option 2 — SSH port forward (same as Spotify). Hermes prints the exact port it bound to in the SSH-session hint. Open a separate terminal on your laptop:

Shellسطر واحد
ssh -N -L <port>:127.0.0.1:<port> user@remote-host

Then open the authorize URL in your browser as normal; the redirect tunnels through and the listener picks it up. Use this when you need the flow to complete unattended (e.g. scripted re-auth where you can't paste interactively).

Pitfall — the 30s config-reload race. If you edit ~/.hermes/config.yaml to add an OAuth MCP server from inside a running Hermes session, the CLI auto-reloads MCP connections with a 30s timeout. That's not enough time to complete an interactive OAuth flow, and the reload will give up. Use hermes mcp login <server> from a fresh terminal instead — it has no such cap and waits the full 5 min for you to paste back.

Why the listener can't just bind 0.0.0.0

شرح للفكرة نفسها. اقرأه ببطء، فبقية الأقسام تبني عليه.

Spotify and most MCP OAuth servers validate the redirect_uri parameter against an allowlist. Both require the loopback form (http://127.0.0.1:<exact-port>/callback). Binding the listener to 0.0.0.0 or a different port would cause the auth server to reject the request as a redirect_uri mismatch. The SSH tunnel keeps the loopback URI intact end-to-end.

Step-by-step: single SSH hop

خطوات عملية بالترتيب. نفّذ خطوة وتأكد أنها نجحت قبل الانتقال للتالية. الأوامر هنا: hermes auth spotify.

1. Start the tunnel from your local machine

Shellسطران
# Spotify (port 43827)
ssh -N -L 43827:127.0.0.1:43827 user@remote-host

-N means "don't open a remote shell, just hold the tunnel open." Keep this terminal running for the duration of the login.

2. In a separate SSH session, run the auth command

Shellسطران
ssh user@remote-host
hermes auth spotify --no-browser

Hermes detects the SSH session, skips the browser auto-open, and prints an authorize URL plus a Waiting for callback on http://127.0.0.1:<port>/callback line.

3. Open the URL in your local browser

Copy the authorize URL from the remote terminal and paste it into the browser on your laptop. Approve the consent screen. The auth server redirects to http://127.0.0.1:<port>/callback. Your browser hits the tunnel, the request is forwarded to the remote listener, and Hermes prints Login successful!.

You can tear down the tunnel (Ctrl+C in the first terminal) once you see the success line.

Step-by-step: through a jump box

خطوات عملية بالترتيب. نفّذ خطوة وتأكد أنها نجحت قبل الانتقال للتالية.

If you reach Hermes through a bastion / jump host, use SSH's built-in -J (ProxyJump):

Shellسطر واحد
ssh -N -L 43827:127.0.0.1:43827 -J jump-user@jump-host user@final-host

This chains a SSH connection through the jump host without putting the loopback port on the jump box itself. The local 127.0.0.1:43827 on your laptop tunnels straight through to 127.0.0.1:43827 on the final remote host.

For older OpenSSH that doesn't support -J, the long form is:

Shell4 أسطر
ssh -N \
    -o "ProxyCommand=ssh -W %h:%p jump-user@jump-host" \
    -L 43827:127.0.0.1:43827 \
    user@final-host

Mosh, tmux, ssh ControlMaster

شرح للفكرة نفسها. اقرأه ببطء، فبقية الأقسام تبني عليه.

The tunnel is a property of the underlying SSH connection. If you're running Hermes inside tmux over a mosh session, the mosh roaming doesn't carry the -L forwarding. Open a separate plain SSH session only for the -L tunnel — that's the connection that has to stay alive during the auth flow. Your interactive mosh/tmux session can keep running Hermes normally.

If you use ssh -o ControlMaster=auto, port forwards on a multiplexed connection share the master's lifetime. Restart the master if the tunnel doesn't come up:

Shellسطران
ssh -O exit user@remote-host
ssh -N -L 43827:127.0.0.1:43827 user@remote-host

Troubleshooting

قسم لحل المشكلات. ابحث فيه عن العطل الذي يشبه حالتك بدل قراءته كاملًا.

bind [127.0.0.1]:43827: Address already in use

Something on your laptop is already using that port. Either the previous tunnel didn't shut down cleanly, or a local Hermes is also listening on it. Find and kill the offender:

Shell3 أسطر
# macOS / Linux
lsof -iTCP:43827 -sTCP:LISTEN
kill <PID>

Then retry the ssh -L command.

Authorization timed out waiting for the local callback

The redirect never made it back to the remote listener. Check the tunnel is still alive (ssh -N doesn't show output, so look at the terminal you started it from), confirm you used the port from the latest Waiting for callback on ... line (Hermes may auto-bump if the preferred port is busy), restart the tunnel if needed, and re-run the auth command.

Tokens land in the wrong ~/.hermes

The tokens are written under the Linux user that ran hermes auth add .... If your gateway / systemd service runs as a different user (e.g. root or a dedicated hermes user), authenticate as that user so the tokens land in their ~/.hermes/auth.json. sudo -u hermes -i or equivalent.

See Also

شرح للفكرة نفسها. اقرأه ببطء، فبقية الأقسام تبني عليه.

اختبار الفهم

سؤالان إجاباتها كلها في هذه الصفحة.

كل خيار اسم حقيقي من توثيق Hermes. حتى الخيارات الخاطئة حقيقية، لكنها من صفحات أخرى.

1. في جدول هذا الدرس، ما «Loopback port» المقابل لـ«xai-oauth (Grok SuperGrok)»؟
2. أي عنوان من التالي لا يظهر في هذا الدرس؟