shellhub-io / shellhub

:computer: Get seamless remote access to any Linux device. Centralized SSH for the edge and cloud computing
https://shellhub.io
Apache License 2.0
1.38k stars 135 forks source link

Command line tool to shellshub #1324

Open leoheck opened 3 years ago

leoheck commented 3 years ago

Hello, how do I connect shellhub form ssh? Do you have any tutorial?

otavio commented 3 years ago

@leoheck thanks for contacting us. Take a look at https://docs.shellhub.io/user-manual/devices/connecting/

leoheck commented 3 years ago

Thanks, I don't need to use shellhub. These browser only applications slow down the whole process. I don't need it at all. But these guys from my team is using it. So, then I was thinking that it would be perfect if you guys coud have a command line tool that connects to the shellhub and allows easy access to the machines there. This would be a real improvement for shelhub.

otavio commented 3 years ago

As mentioned, it is possible to connect from command line as explained on the link I pointed above.

leoheck commented 3 years ago

Maybe I am failing to explain this. I know how use the ssh. I know how to use the shellhub to connect into a device. Now, what I am saying is to have a tool (command line tool), lets call it shellhub

then we cloud do like this

connect to the platform with my credentials $ shellhub leandro password: ****

This is going to ask my password and will give me a terminal with some commands like

list_devices connect_device DEVICE_NAME

Then a advanced user could use this form the command line, and also from a computer that does not provide any gui.

otavio commented 3 years ago

A command-line UI is indeed a very good idea. We need people to help to do it thought. Are you willing to help here?

leoheck commented 3 years ago

Yeah, definitely. Do you have any info to share to get access so I can try something? I was trying briefly to get access to the website from the command line with curl yesterday but the very quick test I made I was seeing a response saying I needed javascript support.

-- Leandro Heck

On Mon, Oct 4, 2021 at 11:07 PM Otavio Salvador @.***> wrote:

A command-line UI is indeed a very good idea. We need people to help to do it thought. Are you willing to help here?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shellhub-io/shellhub/issues/1324#issuecomment-933998601, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJX7YAZTD7ETMFKMNYKISTUFJMVHANCNFSM5FKIM7QA .

otavio commented 3 years ago

We're publishing the OpenAPI docs in next release. Those are a good reference.

gustavosbarreto commented 2 years ago

https://docs.shellhub.io/api

leoheck commented 2 years ago

Beautiful, thanks.

leoheck commented 2 years ago

@gustavosbarreto do you have any example of how I can get a list of my devices with curl?

leoheck commented 2 years ago

more precisely, a list of the ssid fields

leoheck commented 2 years ago

Alright, this is working fine for me.

# Get the Bearer token using cURL and jq
TOKEN=$(curl -s -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' --data "${login_data}" "${URL}/api/login" | jq -r '.token')

Now, how do I get the devices list? I am not getting the devices with this command https://docs.shellhub.io/api/#tag/device/paths/~1api~1devices/get

leoheck commented 2 years ago

It looks like it is getting a single computer.

leoheck commented 2 years ago

Ah, it has query parameters. It would be good to have some examples of the payload in the right panel, maybe.

leoheck commented 2 years ago

Even after using this, I am just getting the first one. image

This is what I am trying right now. image

leoheck commented 2 years ago

ah, it looks like what I want to access is this. https://docs.shellhub.io/api/#tag/session/paths/~1api~1sessions/get

leoheck commented 2 years ago

Or maybe not. There is something weird going on.

leoheck commented 2 years ago

How do I show all my devices? I can just list one. I have at least 20. Do you have any idea?

leoheck commented 2 years ago

Alright, it looks that I am just seeing one of the namespaces. How do I change the namespace?

leoheck commented 2 years ago

This is getting namespaces

Devices count is 17 while devices is 0, this is strange. Sessions is 0 too. Are you sure these numbers are right? I meant, are they returning the right info? image

gustavosbarreto commented 2 years ago

This is getting namespaces

Devices count is 17 while devices is 0, this is strange. Sessions is 0 too. Are you sure these numbers are right? I meant, are they returning the right info? image

@henrybarreto can you please take a look into this?

henrybarreto commented 2 years ago

This is getting namespaces Devices count is 17 while devices is 0, this is strange. Sessions is 0 too. Are you sure these numbers are right? I meant, are they returning the right info? image

@henrybarreto can you please take a look into this?

Yes, I can.

I'll check what is happening.

henrybarreto commented 2 years ago

How do I show all my devices? I can just list one. I have at least 20. Do you have any idea?

Even after using this, I am just getting the first one. image

This is what I am trying right now. image

How do I show all my devices? I can just list one. I have at least 20. Do you have any idea?

Hi, Leo.

If I'm not misleading, --data in cURL is to send a data inside the request's body, but to list devices, you need to send it as query parameters, so your request will become this:

curl -s -X GET  -H 'Authorization: Bearer token' -H 'Accept: application/json' 'localhost/api/devices?per_page=20&page=1'
leoheck commented 2 years ago

Hi. The -d or --data (to send a json) are the same as you are showing. I got more data with the session list instead of the devices list

My current issue is how do I change the namespace. Those commands access my development namespace and couldn't find any way to change the namespace yet.

On Wed, Dec 1, 2021, 23:17 Henry Barreto @.***> wrote:

How do I show all my devices? I can just list one. I have at least 20. Do you have any idea?

Even after using this, I am just getting the first one. [image: image] https://user-images.githubusercontent.com/1277920/144286672-dfd73c77-2ac5-464b-afc6-3609b500b674.png

This is what I am trying right now. [image: image] https://user-images.githubusercontent.com/1277920/144286748-0f39ca0f-821f-4df3-8c27-5c1414dedd6c.png

How do I show all my devices? I can just list one. I have at least 20. Do you have any idea?

Hi, Leo.

If I'm not misleading, --data in cURL is to send a data inside the request's body, but to list devices, you need to send it as query parameters, so your request will become this:

curl -s -X GET -H 'Authorization: Bearer token' -H 'Accept: application/json' 'localhost/api/devices?per_page=20&page=1'

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shellhub-io/shellhub/issues/1324#issuecomment-984230068, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJX7YCNWI42BVTEJNUITEDUO3JKFANCNFSM5FKIM7QA .

henrybarreto commented 2 years ago

Sorry, so. :D

To "change" namespace, you need to do a GET request to http://localhost/api/auth/token/<namespace's tenant>. It will return to you a new token that "points" to this new namespace.

leoheck commented 2 years ago

This was my last try some minutes ago. Let me check... AH, it looks like the /auth/ path was missing...

Please, check your API docs, it looks like it misses this info t/api/auth/token/<namespace's tenant> I tried to locate it now quickly and I was not able to.

leoheck commented 2 years ago

This is what I was trying. Note the different (wrong) URL I was using.

image

leoheck commented 2 years ago

perfect, got the token. now, how do I use it? it is just a matter of replacing the normal token I was using?

henrybarreto commented 2 years ago

This was my last try some minutes ago. Let me check... AH, it looks like the /auth/ path was missing...

Please, check your API docs, it looks like it misses this info t/api/auth/token/<namespace's tenant> I tried to locate it now quickly and I was not able to.

Okay. It is true; I've forgotten this route.

As soon as possible, I'll add this.

Thank you :D

henrybarreto commented 2 years ago

perfect, got the token. now, how do I use it? it is just a matter of replacing the normal token I was using?

Exactly.

leoheck commented 2 years ago

Any suggestion on how do I use the token? Just replacing the token I as using did not work.

leoheck commented 2 years ago

See line 104. this is not working.

image

leoheck commented 2 years ago

ah it worked. it happens that it has just 1 device and no active sessions.

henrybarreto commented 2 years ago

ah it worked. it happens that it has just 1 device and no active sessions.

:D

So... Everything is okay?

leoheck commented 2 years ago

Nice, now it is working! Thank you guys

leoheck commented 2 years ago

Yeah. I was able to get all devices, on all my namespaces.

leoheck commented 2 years ago

Your docs could have curl commands as an example of each command because they are easy to test. Some APIs have this kind of thing. I will share my simple script tomorrow, you could use something to help you improve the docs, if needed.

henrybarreto commented 2 years ago

Your docs could have curl commands as an example of each command because they are easy to test. Some APIs have this kind of thing. I will share my simple script tomorrow, you could use something to help you improve the docs, if needed.

Yeah, you are right, and I'll do.

The API documentation have some points to be improved; examples is one of them.

It seems that your script will be helpful.

leoheck commented 2 years ago

I put some commands I was using, on a gist here https://gist.github.com/leoheck/430698751f17d679d5e9b142280cb03c

I am also using jq as JSON parser.

diegofpk commented 1 year ago

hello guys! all links missing, i want to connect to shellhub's devices via SSh, someone can help please?

otavio commented 1 year ago

Hello @diegofpk,

Please take a look at this link https://docs.shellhub.io/user-guides/devices/connecting#command-line-ssh-client to learn how to connect to a device using the SSH command line.

It's a helpful guide that will walk you through the steps you need to take to establish a secure connection.

Let me know if you have any questions or need further assistance!