Skip to content

Commit b9199ae

Browse files
authored
Merge pull request #134 from Phala-Network/docs/update-ssh-documentation
docs: update SSH documentation with phala ssh command
2 parents 53277cb + 551ebcb commit b9199ae

6 files changed

Lines changed: 220 additions & 163 deletions

File tree

docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@
374374
"/phala-cloud/references/phala-cloud-cli/phala/auth",
375375
"/phala-cloud/references/phala-cloud-cli/phala/cvms",
376376
"/phala-cloud/references/phala-cloud-cli/phala/docker",
377-
"/phala-cloud/references/phala-cloud-cli/phala/simulator"
377+
"/phala-cloud/references/phala-cloud-cli/phala/simulator",
378+
"/phala-cloud/references/phala-cloud-cli/phala/ssh"
378379
]
379380
},
380381
"/phala-cloud/references/migration-from-dstack-v03"

phala-cloud/getting-started/start-from-cloud-ui.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Click the **Deploy** -> **docker-compose.yml** in the top-right corner of the cl
4242
command: "start-notebook.sh --NotebookApp.token=${TOKEN}"
4343
```
4444
45-
3. Choose the **Computing Resources** plan. There are some preset plans available, or you can customize them for more flexibility. In **Node & Image** section, we recommend choosing **dstack-dev-** as guest image if you are deploying for testing. It will enable the debug feature that you can login to the virtual machine in the future.
45+
3. Choose the **Computing Resources** plan. There are some preset plans available, or you can customize them for more flexibility. In **Node & Image** section, we recommend choosing **dstack-dev-** as guest image if you are deploying for testing. This enables [SSH access](/phala-cloud/networking/enable-ssh-access) for debugging.
4646
4747
4848
<Frame caption="Compute Resources">
Lines changed: 59 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,67 @@
11
---
2-
title: Enable SSH Access
2+
title: Enable SSH Access
33
description: Connect to your CVM via SSH for debugging and management
44
---
55

66
<Warning>
7-
SSH access is only available when you deploy with a **dev** OS image. Select "dstack-dev" as the OS type when creating your CVM. Production OS images have SSH disabled for security.
7+
SSH access is only available with **dev** OS images. Select "dstack-dev" when creating your CVM. Production images have SSH disabled for security.
88
</Warning>
99

10-
This guide shows you how to SSH into your CVM through the secure gateway tunnel.
10+
The easiest way to SSH into your CVM is with the Phala CLI. One command connects you through the secure gateway tunnel.
1111

1212
## Prerequisites
1313

14-
- SSH client on your local machine
15-
- OpenSSL installed
14+
- [Phala CLI](/phala-cloud/phala-cloud-cli/overview) (latest version)
1615
- CVM deployed with Development OS
1716

18-
## Step 1: Set Root Credentials
17+
## Step 1: Configure SSH Keys
1918

20-
When deploying your CVM, set one of these environment variables:
19+
Start by adding your SSH keys in **Account Settings > SSH Keys** on the [Phala Cloud dashboard](https://cloud.phala.com/account/settings). You can add keys manually or sync them from GitHub. All saved keys are automatically added to every new CVM you deploy.
2120

22-
**For password authentication:**
23-
- Add `DSTACK_ROOT_PASSWORD` as a secure environment variable
21+
When creating a CVM, the SSH Authorization section lets you add an additional root password or public key specific to that instance. These are added alongside your account keys.
2422

25-
**For key-based authentication (recommended):**
26-
- Add `DSTACK_ROOT_PUBLIC_KEY` with your SSH public key
23+
<Note>
24+
SSH keys are injected **only at CVM creation time**. Updating your account keys won't affect already-deployed CVMs. To modify credentials on existing CVMs, use **Code Update** to set the `DSTACK_ROOT_PASSWORD` or `DSTACK_ROOT_PUBLIC_KEY` environment variables.
25+
</Note>
26+
27+
## Step 2: Connect
28+
29+
```bash
30+
# Connect using phala.toml configuration
31+
phala ssh
32+
33+
# Or specify the CVM name directly
34+
phala ssh my-cvm
35+
```
36+
37+
That's it. The CLI handles the gateway tunnel and SSH configuration automatically.
38+
39+
## Useful Options
40+
41+
The `phala ssh` command supports several options:
42+
43+
```bash
44+
# Preview the SSH command without connecting
45+
phala ssh my-cvm --dry-run
46+
47+
# Enable verbose output for debugging
48+
phala ssh my-cvm -v
49+
50+
# Forward a local port to the CVM
51+
phala ssh my-cvm -- -L 8080:localhost:80
52+
```
2753

28-
If you need to add credentials after deployment, use "Code Update" in the dashboard to modify environment variables.
54+
See the [CLI reference](/phala-cloud/references/phala-cloud-cli/phala/ssh) for all options.
2955

30-
## Step 2: Configure Your SSH Client
56+
<Accordion title="Manual SSH Configuration">
3157

32-
Add this to your `~/.ssh/config` file:
58+
If you prefer manual configuration or need to customize your setup, use `phala ssh --dry-run` to generate the SSH config:
59+
60+
```bash
61+
phala ssh my-cvm --dry-run
62+
```
63+
64+
This outputs a working SSH command you can adapt. The underlying mechanism uses OpenSSL to tunnel SSH through TLS:
3365

3466
```bash
3567
Host my-cvm
@@ -39,21 +71,13 @@ Host my-cvm
3971
ProxyCommand openssl s_client -quiet -connect %h:%p
4072
```
4173

42-
Replace:
43-
- `<app-id>` with your application ID (find it in the dashboard)
44-
- `<cluster>` with your cluster (e.g., `us`)
45-
46-
## Step 3: Connect
74+
Replace `<app-id>` with your application ID and `<cluster>` with your cluster (e.g., `dstack-pha-prod7`).
4775

48-
```bash
49-
ssh my-cvm
50-
```
76+
**macOS users:** If you encounter connection timeouts, you may have LibreSSL instead of OpenSSL. Install OpenSSL via Homebrew and use the full path: `/opt/homebrew/bin/openssl`.
5177

52-
That's it. You're now connected to your CVM through the secure gateway tunnel.
78+
**Windows users:** Install OpenSSL via [Chocolatey](https://chocolatey.org/) (`choco install openssl`) and use the full path in ProxyCommand. Alternatively, use WSL where the Linux instructions work directly.
5379

54-
<Note>
55-
**macOS users:** If you encounter connection timeouts, you may have LibreSSL instead of OpenSSL. Install OpenSSL via Homebrew (`brew install openssl`) and update your ProxyCommand to use the full path to the Homebrew OpenSSL binary.
56-
</Note>
80+
</Accordion>
5781

5882
## What You Can Do
5983

@@ -71,82 +95,18 @@ docker stats
7195
# Debug networking
7296
curl http://localhost:8080
7397
netstat -tulpn
74-
wg show
7598
```
7699

77-
## Security Notes
78-
79-
- SSH traffic is tunneled through TLS via the gateway
80-
- Only your code inside the TEE can see the decrypted SSH session
81-
- Use key-based authentication for production debugging
82-
- Remember to switch to Production OS when you're done debugging
83-
84-
## Windows SSH Access
85-
86-
Windows users can connect to CVMs using PowerShell or Windows Terminal with OpenSSL.
87-
88-
### Option 1: Using Windows OpenSSL
89-
90-
1. **Install OpenSSL for Windows:**
91-
- Download from [slproweb.com/products/Win32OpenSSL.html](https://slproweb.com/products/Win32OpenSSL.html)
92-
- Or install via Chocolatey: `choco install openssl`
93-
94-
2. **Create SSH config file:**
95-
96-
Create or edit `C:\Users\<YourUsername>\.ssh\config`:
97-
```
98-
Host my-cvm
99-
HostName <app-id>-22.<cluster>.phala.network
100-
User root
101-
Port 443
102-
ProxyCommand "C:\Program Files\OpenSSL-Win64\bin\openssl.exe" s_client -quiet -connect %h:%p
103-
```
104-
105-
3. **Connect:**
106-
```powershell
107-
ssh my-cvm
108-
```
109-
110-
### Option 2: Using WSL (Windows Subsystem for Linux)
111-
112-
If you have WSL installed, the Linux instructions work directly:
113-
114-
1. Open WSL terminal
115-
2. Edit `~/.ssh/config` as shown in the main guide
116-
3. Connect with `ssh my-cvm`
117-
118-
### Option 3: Using PuTTY with Plink
119-
120-
1. Install [PuTTY](https://www.putty.org/)
121-
2. Use Plink with OpenSSL tunneling:
122-
```powershell
123-
plink -proxycmd "openssl s_client -quiet -connect <app-id>-22.<cluster>.phala.network:443" root@<app-id>-22.<cluster>.phala.network
124-
```
125-
126-
<Note>
127-
**Windows OpenSSL Path:** If you installed OpenSSL to a different location, update the path in the ProxyCommand accordingly.
128-
</Note>
100+
<Tip>
101+
Remember to switch to a Production OS image when you're done debugging.
102+
</Tip>
129103

130104
## Troubleshooting
131105

132-
**Permission denied?**
133-
- Verify your credentials are set in environment variables
134-
- Use "Code Update" to add them if forgotten during deployment
135-
136-
**Connection timeout?**
137-
- Check your OpenSSL version: `openssl version`
138-
- macOS users: ensure you're using OpenSSL, not LibreSSL
139-
- Windows users: verify OpenSSL is in your PATH or use the full path
140-
141-
**Connection refused?**
142-
- Confirm you deployed with Development OS, not Production OS
143-
144-
**Windows: 'openssl' is not recognized**
145-
- Install OpenSSL and add it to your system PATH
146-
- Or use the full path to openssl.exe in the ProxyCommand
147-
148-
## Next Steps
106+
| Issue | Solution |
107+
|-------|----------|
108+
| Permission denied | Check Account Settings for saved keys. For existing CVMs, use Code Update to set credentials. |
109+
| Connection refused | Confirm you deployed with Development OS, not Production |
110+
| Connection timeout | Run `phala ssh -v` to see detailed connection info |
149111

150-
- [Monitor logs](/phala-cloud/monitoring/public-logs)
151-
- [Set up custom domains](/phala-cloud/networking/setup-custom-domain)
152-
- [Learn about security](/phala-cloud/networking/security)
112+
For more detailed troubleshooting, see [Networking Troubleshooting](/phala-cloud/networking/troubleshooting#ssh-access-denied).

phala-cloud/networking/troubleshooting.mdx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,32 +211,34 @@ grpcurl -plaintext localhost:50051 list
211211

212212
SSH only works with development OS images. Production images have SSH disabled.
213213

214-
### Check Configuration
214+
### Debug with Verbose Mode
215+
216+
Use the Phala CLI with verbose output to diagnose connection issues:
215217

216218
```bash
217-
# Verify environment variables are set
218-
DSTACK_ROOT_PASSWORD=yourpassword
219-
# OR
220-
DSTACK_ROOT_PUBLIC_KEY=ssh-rsa AAAA...
219+
phala ssh my-cvm -v
220+
```
221221

222-
# Test connection
223-
ssh -v my-cvm
222+
This shows detailed connection information including gateway resolution and SSH handshake.
224223

225-
# Test ProxyCommand directly
226-
openssl s_client -connect <app-id>-22.dstack-prod5.phala.network:443
227-
```
224+
### Check SSH Keys
225+
226+
SSH keys from Account Settings are only injected at CVM creation time. If you added keys after deployment, use Code Update to set `DSTACK_ROOT_PUBLIC_KEY`.
228227

229228
### macOS OpenSSL Issue
230229

231-
macOS uses LibreSSL which may cause issues:
230+
If using manual SSH configuration, macOS LibreSSL may cause timeouts:
231+
232232
```bash
233233
# Install OpenSSL via Homebrew
234234
brew install openssl
235235

236-
# Update SSH config
237-
ProxyCommand /opt/homebrew/bin/openssl s_client -quiet -connect %h:%p
236+
# Use full path in ProxyCommand
237+
/opt/homebrew/bin/openssl s_client -quiet -connect %h:%p
238238
```
239239

240+
For detailed SSH setup, see [Enable SSH Access](/phala-cloud/networking/enable-ssh-access).
241+
240242
## Debugging Commands
241243

242244
### From Outside CVM
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
description: Connect to a CVM via SSH through the secure gateway tunnel.
3+
title: ssh
4+
---
5+
6+
## Command: `ssh`
7+
8+
#### Syntax
9+
10+
```
11+
phala ssh [options] [<cvm-name>] [--] [...]
12+
```
13+
14+
### Description
15+
16+
The `phala ssh` command connects you to a CVM via SSH through the secure gateway tunnel. It handles all the gateway configuration automatically.
17+
18+
```bash
19+
Usage: phala ssh [options] [<cvm-name>] [--] [...]
20+
21+
Connect to a CVM via SSH
22+
23+
Arguments:
24+
<cvm-name>? CVM name. If not provided, reads from phala.toml
25+
26+
Options:
27+
-h, --help Show help information
28+
-p, --port <value> Gateway port (default: 443)
29+
-g, --gateway <value> Gateway domain (skips API call for offline usage)
30+
-t, --timeout <value> Connection timeout in seconds (default: 30)
31+
-v, --verbose Show verbose connection details
32+
--dry-run Print the SSH command without executing it
33+
34+
Pass-through (after --):
35+
All arguments after -- are passed directly to ssh.
36+
```
37+
38+
### Examples
39+
40+
* Connect using phala.toml configuration
41+
42+
```bash
43+
phala ssh
44+
```
45+
46+
* Connect to a specific CVM
47+
48+
```bash
49+
phala ssh my-app
50+
```
51+
52+
* Preview the SSH command without connecting
53+
54+
```bash
55+
phala ssh my-app --dry-run
56+
```
57+
58+
<details>
59+
60+
<summary>Example Output</summary>
61+
62+
```bash
63+
ssh -o ProxyCommand="openssl s_client -quiet -connect %h:%p" \
64+
-o StrictHostKeyChecking=no \
65+
root@abc123def456-22.dstack-prod5.phala.network -p 443
66+
```
67+
68+
</details>
69+
70+
* Connect with verbose output for debugging
71+
72+
```bash
73+
phala ssh my-app -v
74+
```
75+
76+
* Forward a local port to the CVM
77+
78+
```bash
79+
phala ssh my-app -- -L 8080:localhost:80
80+
```
81+
82+
This forwards your local port 8080 to port 80 on the CVM.
83+
84+
* Set up a SOCKS proxy
85+
86+
```bash
87+
phala ssh my-app -- -D 1080 -N
88+
```
89+
90+
This creates a SOCKS proxy on local port 1080 without executing a remote command.
91+
92+
* Execute a remote command
93+
94+
```bash
95+
phala ssh my-app -- docker ps -a
96+
```
97+
98+
* Connect with a custom SSH key
99+
100+
```bash
101+
phala ssh my-app -- -i ~/.ssh/custom_key
102+
```
103+
104+
* Offline mode (skip API lookup)
105+
106+
```bash
107+
phala ssh my-app -g dstack-prod5.phala.network -p 443
108+
```
109+
110+
When you specify the gateway domain, the CLI skips the API call and connects directly.
111+
112+
### Pass-through Options
113+
114+
Any arguments after `--` are passed directly to the underlying SSH command. Common options include:
115+
116+
| Option | Description |
117+
|--------|-------------|
118+
| `-i <keyfile>` | Use a specific identity file |
119+
| `-L <local>:<remote>` | Local port forwarding |
120+
| `-R <remote>:<local>` | Remote port forwarding |
121+
| `-D <port>` | Dynamic SOCKS proxy |
122+
| `-v` | SSH verbose mode |
123+
124+
<Note>
125+
The `-o ProxyCommand` option is blocked since the CLI manages the proxy configuration automatically.
126+
</Note>

0 commit comments

Comments
 (0)