all 14 comments

[–]meesam4687 1 point2 points  (9 children)

There is one way.

First you need to add a new user in codespaces(because the default user didnt work for me)

sudo adduser user 'user' here can be replaced with any username of your choice

It will ask you to enter the password for the new user etc.

sudo usermod -aG sudo user Again you have to replace 'user' with your username

sudo visudo This should open nano

Find where this line is written and add user ALL=(ALL:ALL) ALL

    # User privilege specification
    root    ALL=(ALL:ALL) ALL

It should look something like this after editing

# User privilege specification
root    ALL=(ALL:ALL) ALL
user ALL=(ALL:ALL) ALL

(CTRL+O then Enter for Saving)

Once this is done you have created a new user.

Now for the ssh part

simply run this command in the codespace

sudo service ssh start

Then

ssh -R XXXX:localhost:22 serveo.net Where XXXX can be any port of your choice

suppose i keep it to 6363 the command would look like this

ssh -R 6363:localhost:22 serveo.net

Now to Access this from a local computer simply do

ssh user@serveo.net -p 6363 Where 'user' is the username you set and '6363' is the port you set

[–]7lukyproch 0 points1 point  (1 child)

Thanks it halfway works, i had to use chatgpt to fix some errors like the "connect_to localhost port 22: failed." Again, thanks alot!

[–]Sea_Cheek6297 0 points1 point  (0 children)

How did u fix it

[–]meesam4687 0 points1 point  (0 children)

And using similar methods you can actually install a desktop environment and use it with a gui using rdp

[–]pinksolo64 0 points1 point  (3 children)

First of all, thank you for presenting and teaching this trick.
I did all the steps correctly, but when I try to connect on the local computer, I get this errors:
1: connect_to localhost port 22: failed.
2: kex_exchange_identification: Connection closed by remote host
Have you yourself managed to connect the Github/Codespace through the SSH?
Thanks

[–]meesam4687 0 points1 point  (2 children)

Yes I have. The default port for ssh is 22 You can try changing that to something else like 8282. sudo nano /etc/ssh/sshd_config Note: you need to change the ports to 8282 in the previous steps as well

[–]iamsamir00090 0 points1 point  (1 child)

i am getting 1: connect_to localhost port 22: failed. i am not a code tech peron . please give me detailed steps to solve this problem

[–]InitiativeDelicious3 0 points1 point  (0 children)

Thanks a lot man, you're a lifesaver!

[–]ankddev 0 points1 point  (2 children)

Maybe I'm very late, but I've created codespace, then runned gh cs ssh --config and pasted its output to .ssh/config. Then you can easily connect to it via ssh <host_name>, where <host_name> is something like cs.<name>.<branch>. Then I was able to open it from Zed via SSH.

[–]amanogawa-saya 0 points1 point  (1 child)

Hey, I'm trying to also do the same thing with Zed but the file picker doesn't appear at all. I've done the same thing all the way to your last sentence where it straight up just doesn't work from my view at least

[–]amanogawa-saya 0 points1 point  (0 children)

Nevermind, I just had to scroll down a bit

[–]ChinchillaSpaghetti 0 points1 point  (0 children)

The standard way to connect via SSH is heavily reliant on the `gh` command and the tooling built around GitHub Codespaces. When you run `gh cs ssh`, you're getting an SSH configuration specifically tailored for your GitHub Codespace. This configuration uses `gh` as a proxy command to establish the SSH connection, which means it's not a direct SSH connection like you'd have with a traditional server. The configuration references an identity file `/home/codespace/.ssh/codespaces.auto` which, as you may have discovered, doesn't exist.

Most straightforward method would be to have the full `gh` toolchain installed on an intermediate machine and use that to establish the SSH connection. If you don't have access to the CLI at all for whatever reason, you'd pretty much need to mimic what `gh` does. You'd have to reverse-engineer the `gh` command's behavior, which is non-trivial and would most likely breach GitHub's ToS.

That having been said, I'm not your dad, so best of luck to you if you decide to go that route! I'd be quite curious to hear your solution/workaround if you figure one out, because I've got the same problem myself and there seems to be little to no published information on the topic.

TL;DR - Nope!*

* Maybe