pohmelie / cuda_ftp

FTP plugin for CudaText (http://www.uvviewsoft.com/cudatext) editor
5 stars 3 forks source link

Parse default ssh files #57

Open lfromanini opened 3 years ago

lfromanini commented 3 years ago

Perhaps this is more a feature request than an issue. The FTP plugin should read $HOME/.ssh/config file to retrieve hosts information if available - this will also allow the user to give alias to his hosts. Besides, it must try the default identity file $HOME/.ssh/id_rsa if exists.

Alexey-T commented 3 years ago

I'm not sure about this, because no $HOME/.ssh/config here.

lfromanini commented 3 years ago

I'm not sure about this, because no $HOME/.ssh/config here.

You can check how it works here: Using the SSH Config File, but a good summary is:

Host dev
    HostName dev.example.com
    User john
    Port 2322

When you type ssh dev, the ssh client will read the configuration file and use the connection details that are specified for the dev host. This approach will be very useful to have in this add-on. Besides, I can test it to you, in case you need.

Alexey-T commented 3 years ago

In this case, Cud plugin will behave differently on Win and Linux? on Linux it must suggest additional hosts? not ok.

lfromanini commented 3 years ago

In this case, Cud plugin will behave differently on Win and Linux? on Linux it must suggest additional hosts? not ok.

Definitively, it should be the same behavior. In POSIX (Linux, Unix, BSD, Mac), the default ssh config file location is $HOME/.ssh/config and default identity file is $HOME/.ssh/id_rsa. For Windows, the variable that points to home folder is %USERPROFILE%. In case of Windows, ssh config file is located at %USERPROFILE%\.ssh\config and identity file is %USERPROFILE%\.ssh\id_rsa. They share the exactly same folder tree structure. The only difference is the variable for home folder information (and, of course, the slash and backslash but this is handled by Python itself).

Python offers a way to solve it, agnostic to the OS:

>>> import os
>>> os.path.expanduser("~")

Concatenate it with .ssh/config and .ssh/id_rsa and you'll have the same code for both OSes.

edit: I tested here in Linux and Windows and the home folder expansion worked fine