| name | remote-codespaces |
| description | Procedural instructions on tunneling and exposing GH Codespaces over SSH/SFTP directly to Termux. |
Why this setup works, including all the moving parts, your “surprises,” and parallels with GCloud. This is aimed at any AI trying to understand and reproduce the behavior reliably.
Dynamic Userspace Mount of Codespaces via Termux / MiXplorer
1️⃣ Environment Overview
We are dealing with:
- GitHub Codespaces (remote ephemeral Linux environment).
- Termux (local Android environment, where MiXplorer lives).
- Tools involved:
gh CLI, rclone, SSHFS (optional), sudo, FUSE, MiXplorer.
- Objective: Provide a MiXplorer-style userspace mount of the Codespace, without using public IPs, without local passwords or keys, fully tunneled via SSH.
2️⃣ Determine Codespace Workspace Path
- Authenticate
gh:
gh auth login --with-token < ~/.ghtoken1
- This logs into GitHub and stores an ephemeral token in
gh’s session.
- Token must have
codespace scope.
- Select Available Codespace:
CSPACE_NAME=$(gh codespace list --json name,state | jq -r '.[] | select(.state=="Available") | .name' | head -n1)
- Picks the first Available Codespace.
- Ensures we are operating only on live, accessible instances.
- Determine workspace path inside Codespace:
WORKSPACE_PATH=$(gh codespace ssh -c "$CSPACE_NAME" -- 'pwd' | tr -d '\r\n')
- Codespaces may have different home/workspace paths.
- This avoids assumptions like
/workspace (which can fail).
✅ Now we know the exact remote path we want to expose via SFTP/FUSE.
3️⃣ Start rclone SFTP server inside Codespace
- Start
rclone serve sftp remotely:
gh codespace ssh -c "$CSPACE_NAME" -- \
"nohup rclone serve sftp $WORKSPACE_PATH --addr :2222 >/dev/null 2>&1 &"
- Starts a remote SFTP server inside the Codespace at
:2222.
nohup ensures it continues running after the SSH session ends.
- Port forwarding to Termux (localhost):
gh codespace ssh -c "$CSPACE_NAME" -- -L 2222:localhost:2222 -N &
- Establishes a local port on Termux (here, 2222) pointing to the remote SFTP.
- Any local client (MiXplorer, rclone, SSHFS) sees it as
127.0.0.1:2222.
✅ The tunnel makes the remote Codespace appear local.
4️⃣ Why MiXplorer can connect without keys or password
-
SSH authentication has already been handled by gh:
gh uses the token from ~/.ghtoken1 to log in to the Codespace.
- It sets up an ephemeral SSH session with an internal, temporary key.
- The port-forwarded SFTP inherits this authenticated session.
-
MiXplorer connects as codespace, the actual Linux user in Codespace.
-
No password is required because the SSH session has already pre-authenticated.
-
No private key file is needed for MiXplorer; the tunnel handles all authentication.
Surprise tricks:
- Local clients treat the connection as a “normal SFTP” session, but it is actually tunneled and pre-authenticated.
- This is why specifying
pem_private_key_path or entering a password is unnecessary.
5️⃣ Mounting via rclone or FUSE in Termux
- On Termux, you can mount the tunneled SFTP:
RCLONE_REMOTE="GH_01"
MOUNT_PATH=~/storage/GH_01_rclone
if ! rclone listremotes | grep -qx "${RCLONE_REMOTE}:"; then
rclone config create "$RCLONE_REMOTE" sftp \
host 127.0.0.1 \
user codespace \
port 2222
fi
mkdir -p "$MOUNT_PATH"
sudo rclone mount "$RCLONE_REMOTE:" "$MOUNT_PATH" \
--allow-other \
--vfs-cache-mode writes &
- FUSE allows user-space filesystem access.
sudo may be required to satisfy allow-other.
- Mount point now behaves like a local directory in MiXplorer.
6️⃣ Parallels with GCloud Cloud Shell
-
GCloud workflow:
- Cloud Shell has a public IP or ephemeral port.
- You fetch the IP via
gcloud cloud-shell ssh --authorize-session "curl -s https://ipinfo.io/ip"
- You create an rclone SFTP remote pointing to that IP and SSH key (PEM).
- MiXplorer sees the mount via local SSHFS or FUSE.
-
Codespaces workflow is conceptually the same:
| GCloud | Codespaces / gh CLI |
|---|
| PEM key needed | Not needed — gh tunnel pre-authenticated |
| User: cloud shell | User: codespace |
| Fetch external IP | Tunnel via localhost |
| Mount via SSHFS or rclone | Mount via rclone FUSE |
| MiXplorer sees filesystem | Same |
-
Main surprise: Codespaces works without password or key, but GCloud does not.
7️⃣ Why this works reliably
- Step 1:
gh auth login ensures gh can access Codespace.
- Step 2:
gh codespace ssh starts a session and/or tunnel.
- Step 3:
rclone serve sftp inside Codespace exposes the filesystem.
- Step 4: Local port forward makes it appear local (
127.0.0.1:2222).
- Step 5: MiXplorer or
rclone mount accesses it as a local SFTP mount.
Tricks for AIs to notice:
- Pre-authenticated SSH tunnel eliminates password/key requirement.
- Workspace path must be determined dynamically (
pwd in Codespace).
rclone serve sftp inside Codespace + local port forward replaces the need for public IPs.
- FUSE mount in Termux gives a MiXplorer-style file browsing experience.
- Sudo may be needed for
allow-other in FUSE mounts.
✅ Conclusion for AI readers
This is a clean pattern for ephemeral cloud workspaces:
- Authenticate via provider CLI (
gh or gcloud).
- Determine workspace path dynamically.
- Start SFTP server inside the remote environment.
- Forward remote port to localhost.
- Mount locally via FUSE/rclone/SSHFS.
- MiXplorer (or any SFTP client) sees a fully browsable filesystem, pre-authenticated.
The magic of Codespaces is the ephemeral SSH session created by gh, which allows no-key, no-password SFTP through the tunnel. GCloud works similarly, but uses PEM keys because authentication is not tunneled.
Working codes are in:
/sdcard/Documents/Android_Code_snippets/aliases2.sh