Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command line tool to shellshub #1324

Open
leoheck opened this issue Oct 4, 2021 · 41 comments
Open

Command line tool to shellshub #1324

leoheck opened this issue Oct 4, 2021 · 41 comments
Labels
Milestone

Comments

@leoheck
Copy link

leoheck commented Oct 4, 2021

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

@otavio
Copy link
Member

otavio commented Oct 4, 2021

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

@leoheck
Copy link
Author

leoheck commented Oct 5, 2021

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
Copy link
Member

otavio commented Oct 5, 2021

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

@leoheck
Copy link
Author

leoheck commented Oct 5, 2021

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 otavio added this to the Future milestone Oct 5, 2021
@otavio otavio added area/cli area/ui kind/feature New feature or request labels Oct 5, 2021
@otavio
Copy link
Member

otavio commented Oct 5, 2021

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
Copy link
Author

leoheck commented Oct 5, 2021 via email

@otavio
Copy link
Member

otavio commented Oct 5, 2021

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

@gustavosbarreto
Copy link
Member

gustavosbarreto commented Dec 1, 2021

@leoheck
Copy link
Author

leoheck commented Dec 1, 2021 via email

@leoheck
Copy link
Author

leoheck commented Dec 1, 2021

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

@leoheck
Copy link
Author

leoheck commented Dec 1, 2021

more precisely, a list of the ssid fields

@leoheck
Copy link
Author

leoheck commented Dec 1, 2021

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
Copy link
Author

leoheck commented Dec 1, 2021

It looks like it is getting a single computer.

@leoheck
Copy link
Author

leoheck commented Dec 1, 2021

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

@leoheck
Copy link
Author

leoheck commented Dec 1, 2021

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

This is what I am trying right now.
image

@leoheck
Copy link
Author

leoheck commented Dec 1, 2021

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

@leoheck
Copy link
Author

leoheck commented Dec 1, 2021

Or maybe not. There is something weird going on.

@leoheck
Copy link
Author

leoheck commented Dec 1, 2021

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

@leoheck
Copy link
Author

leoheck commented Dec 2, 2021

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

@leoheck
Copy link
Author

leoheck commented Dec 2, 2021

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Author

leoheck commented Dec 2, 2021 via email

@henrybarreto
Copy link
Member

henrybarreto commented Dec 2, 2021

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
Copy link
Author

leoheck commented Dec 2, 2021

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
Copy link
Author

leoheck commented Dec 2, 2021

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

image

@leoheck
Copy link
Author

leoheck commented Dec 2, 2021

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

@henrybarreto
Copy link
Member

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
Copy link
Member

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
Copy link
Author

leoheck commented Dec 2, 2021

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

@leoheck
Copy link
Author

leoheck commented Dec 2, 2021

See line 104. this is not working.

image

@leoheck
Copy link
Author

leoheck commented Dec 2, 2021

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

@henrybarreto
Copy link
Member

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

:D

So... Everything is okay?

@leoheck
Copy link
Author

leoheck commented Dec 2, 2021

Nice, now it is working! Thank you guys

@leoheck
Copy link
Author

leoheck commented Dec 2, 2021

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

@leoheck
Copy link
Author

leoheck commented Dec 2, 2021

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
Copy link
Member

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
Copy link
Author

leoheck commented Dec 2, 2021

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
Copy link

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

@otavio
Copy link
Member

otavio commented Aug 10, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants