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

Support reading remote files via ssh, sftp, and any other network drives #426

Closed
alanhamlett opened this issue May 28, 2021 · 16 comments · Fixed by #623
Closed

Support reading remote files via ssh, sftp, and any other network drives #426

alanhamlett opened this issue May 28, 2021 · 16 comments · Fixed by #623
Assignees

Comments

@alanhamlett
Copy link
Member

No description provided.

@gandarez
Copy link
Member

@alanhamlett is that a feature already implemented in python?

@gandarez gandarez added feature and removed triage labels May 29, 2021
@alanhamlett
Copy link
Member Author

Partially with https://github.com/wakatime/wakatime/issues/72 but we didn't support ssh:// nor sftp:// yet.

@gandarez gandarez self-assigned this May 29, 2021
@gandarez gandarez moved this from To do to In progress in wakatime-cli May 29, 2021
@gandarez
Copy link
Member

Ok thanks. Taking this 👍

@gandarez gandarez moved this from In progress to To do in wakatime-cli Jul 1, 2021
@tshu-w
Copy link

tshu-w commented Aug 8, 2021

vote for this

@gandarez gandarez moved this from To do to In progress in wakatime-cli Jan 4, 2022
wakatime-cli automation moved this from In progress to Done Jan 7, 2022
@alanhamlett
Copy link
Member Author

Thank you @gandarez for implementing remote file support with #623!!1!

@tshu-w
Copy link

tshu-w commented Jan 8, 2022

Hi, are there any instructions on the format of the remote files entity, starting with ssh:// or sftp://? Where to write the hostname? I thought I can make a PR for https://github.com/wakatime/wakatime-mode/blob/master/wakatime-mode.el#L125

@tshu-w
Copy link

tshu-w commented Feb 19, 2022

@gandarez @alanhamlett Hi, I try with this format ssh://hostname/path/to/file from this PR and it seems like wakatime doesn't read ssh config which complain about host name and cannot use ssh key.

@alanhamlett
Copy link
Member Author

Can you normally ssh to that host without entering a password? You might need to add the authorized ssh key to your ~/.ssh/ folder. I think the default is id_rsa.

@tshu-w
Copy link

tshu-w commented Feb 22, 2022

Can you normally ssh to that host without entering a password?

Yes.

$ killall ssh
$ ssh -p PORT IP ls /home/wangtianshu/test_project/test.py
/home/wangtianshu/test_project/test.py
$ wakatime-cli --entity ssh://IP:PORT/home/wangtianshu/test_project/test.py --plugin emacs-wakatime/1.0.2

.wakatime.log:

{"caller":"github.com/wakatime/wakatime-cli/pkg/remote/remote.go:188","func":"Connect","level":"warning","message":"no host key found for IP. It will try to make an insecure connection","now":"2022-02-22T17:17:27+08:00","version":"v1.37.0"}
{"caller":"github.com/wakatime/wakatime-cli/pkg/remote/remote.go:88","func":"1","level":"error","message":"failed to download file to temporary folder: failed to connect to sftp host: failed to connecto to 'IP:PORT': ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain","now":"2022-02-22T17:17:27+08:00","version":"v1.37.0"}
{"caller":"github.com/wakatime/wakatime-cli/pkg/language/chroma.go:128","func":"selectByCustomizedPriority","level":"warning","message":"failed to load folder extensions: failed to read directory: open ssh://IP:PORT/home/wangtianshu/test_project/: no such file or directory","now":"2022-02-22T17:17:27+08:00","version":"v1.37.0"}

and it seems like wakatime doesn't obey .ssh/config:

HOST hostalias
  Hostname IP
  User wangtianshu
  Port PORT

and run wakatime-cli --entity ssh://hostalias/home/wangtianshu/test_project/test.py --plugin emacs-wakatime/1.0.2 got:

{"caller":"github.com/wakatime/wakatime-cli/pkg/remote/remote.go:188","func":"Connect","level":"warning","message":"no host key found for hostalias. It will try to make an insecure connection","now":"2022-02-22T17:20:03+08:00","version":"v1.37.0"}
{"caller":"github.com/wakatime/wakatime-cli/pkg/remote/remote.go:88","func":"1","level":"error","message":"failed to download file to temporary folder: failed to connect to sftp host: failed to connecto to 'hostalias:22': dial tcp: lookup jumpbox: no such host","now":"2022-02-22T17:20:03+08:00","version":"v1.37.0"}
{"caller":"github.com/wakatime/wakatime-cli/pkg/language/chroma.go:128","func":"selectByCustomizedPriority","level":"warning","message":"failed to load folder extensions: failed to read directory: open ssh://hostalias/home/wangtianshu/test_project/: no such file or directory","now":"2022-02-22T17:20:03+08:00","version":"v1.37.0"}

@gandarez
Copy link
Member

It tries to get ssh public key from ~/.ssh/knwon_hosts. Could you please double check if you have added it before and should be there?

@tshu-w
Copy link

tshu-w commented Feb 22, 2022

are you sure it is ~/.ssh/knwon_hosts?

The known_hosts File is a client file containing all remotely connected known hosts

@gandarez
Copy link
Member

are you sure it is ~/.ssh/knwon_hosts?

The known_hosts File is a client file containing all remotely connected known hosts

yep, there's.

@tshu-w
Copy link

tshu-w commented Feb 22, 2022

I also get error with username and password provide:

wakatime-cli --entity ssh://USER:PASS@IP:PORT/home/wangtianshu/test_project/test.py

@tshu-w
Copy link

tshu-w commented Feb 22, 2022

are you sure it is ~/.ssh/knwon_hosts?

The known_hosts File is a client file containing all remotely connected known hosts

yep, there's.

I still got no host key found for IP even if I ssh user@ip -p port and press yes to add host key to ~/.ssh/knwon_hosts

I'm quite sure because the content in known_hosts seems be hashed but I think it's added as trashed and ssh, a new line was added.

@gandarez
Copy link
Member

gandarez commented Feb 22, 2022

Could you please check if there's a line in this format IP <algorithm> <hash>?

example:

192.168.1.200 ssh-ed25519 <hash>

@tshu-w
Copy link

tshu-w commented Feb 23, 2022

@gandarez Sorry for not being clear. I open a new issue with minimal setup #658

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

Successfully merging a pull request may close this issue.

3 participants