Skip to content

Commit 501dc01

Browse files
committed
Fix SSH template: add sudo, root user for runCmd, and ssh-keygen at start time
Tested and verified working: - Template builds successfully - SSH connection works with websocat proxy - Password authentication with user:sandbox credentials
1 parent f976e40 commit 501dc01

2 files changed

Lines changed: 15 additions & 18 deletions

File tree

docs/sandbox/ssh-access.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ You can either build a [custom template](/docs/template/examples/ssh-ready) or s
8181
```bash
8282
# Install SSH server and websocat
8383
sudo apt-get update && sudo apt-get install -y openssh-server curl
84-
sudo mkdir -p /run/sshd
8584
sudo curl -fsSL -o /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl
8685
sudo chmod a+x /usr/local/bin/websocat
8786

8887
# Set a password for the user
8988
echo "user:sandbox" | sudo chpasswd
9089

91-
# Start SSH and the WebSocket proxy
90+
# Generate host keys, start SSH daemon and WebSocket proxy
91+
sudo mkdir -p /run/sshd
92+
sudo ssh-keygen -A
9293
sudo /usr/sbin/sshd
9394
websocat -b --exit-on-eof ws-l:0.0.0.0:8081 tcp:127.0.0.1:22
9495
```

docs/template/examples/ssh-ready.mdx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,18 @@ import { Template, waitForPort } from 'e2b'
1313

1414
export const template = Template()
1515
.fromUbuntuImage('22.04')
16-
// Install SSH server and websocat for WebSocket proxying
17-
.aptInstall(['openssh-server', 'curl'])
16+
// Install SSH server, curl for downloading websocat, and sudo for start command
17+
.aptInstall(['openssh-server', 'curl', 'sudo'])
18+
// Configure SSH and download websocat (requires root)
1819
.runCmd([
1920
'curl -fsSL -o /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl',
2021
'chmod a+x /usr/local/bin/websocat',
21-
])
22-
// Configure SSH with password authentication
23-
.runCmd([
24-
'mkdir -p /run/sshd',
2522
"sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config",
2623
'echo "user:sandbox" | chpasswd',
27-
])
24+
'echo "user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers',
25+
], { user: 'root' })
2826
// Start SSH daemon and WebSocket proxy on port 8081
29-
.setStartCmd('/usr/sbin/sshd && websocat -b --exit-on-eof ws-l:0.0.0.0:8081 tcp:127.0.0.1:22', waitForPort(8081))
27+
.setStartCmd('sudo mkdir -p /run/sshd && sudo ssh-keygen -A && sudo /usr/sbin/sshd && websocat -b --exit-on-eof ws-l:0.0.0.0:8081 tcp:127.0.0.1:22', waitForPort(8081))
3028
```
3129

3230
```python Python
@@ -36,20 +34,18 @@ from e2b import Template, wait_for_port
3634
template = (
3735
Template()
3836
.from_ubuntu_image("22.04")
39-
# Install SSH server and websocat for WebSocket proxying
40-
.apt_install(["openssh-server", "curl"])
37+
# Install SSH server, curl for downloading websocat, and sudo for start command
38+
.apt_install(["openssh-server", "curl", "sudo"])
39+
# Configure SSH and download websocat (requires root)
4140
.run_cmd([
4241
"curl -fsSL -o /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl",
4342
"chmod a+x /usr/local/bin/websocat",
44-
])
45-
# Configure SSH with password authentication
46-
.run_cmd([
47-
"mkdir -p /run/sshd",
4843
"sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config",
4944
'echo "user:sandbox" | chpasswd',
50-
])
45+
'echo "user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers',
46+
], user="root")
5147
# Start SSH daemon and WebSocket proxy on port 8081
52-
.set_start_cmd("/usr/sbin/sshd && websocat -b --exit-on-eof ws-l:0.0.0.0:8081 tcp:127.0.0.1:22", wait_for_port(8081))
48+
.set_start_cmd("sudo mkdir -p /run/sshd && sudo ssh-keygen -A && sudo /usr/sbin/sshd && websocat -b --exit-on-eof ws-l:0.0.0.0:8081 tcp:127.0.0.1:22", wait_for_port(8081))
5349
)
5450
```
5551

0 commit comments

Comments
 (0)