veeso / termscp

🖥 A feature rich terminal UI file transfer and explorer with support for SCP/SFTP/FTP/S3/SMB
https://termscp.veeso.dev
MIT License
1.55k stars 46 forks source link

[QUESTION] - How to connect to remote server using ssh config? #149

Closed namespaceYcZ closed 1 year ago

namespaceYcZ commented 1 year ago

Some basic background info: I have some Linux virtual machines, for some reason they need to use dhcp and their ip addresses change often. I wrote a script to detect their ip addresses (using arp util) and write to the hosts file of the host machine, so that I don't have to change my ssh config or any other config file that use the services on those virtual machines. 2023-02-23_203855

I can always log in to these virtual machines with a fixed ssh command just like this(ssh cross-platform where "cross-platform" is the hostname in the ssh config file): 2023-02-23_202140 (because I have set up my ssh config and added my public key to the authorized_keys file so I do not have to offer my password) 2023-02-23_201702

(I can always ssh to it after using the script to detect its IP address even if the IP address of this virtual machine changes). Now, how can I use termscp to connect to the remote server using ssh config? (I have check the config of termscp's default config, which is ok: 2023-02-23_203347

  1. using hostname in tui: 2023-02-23_203518 2023-02-23_203535
  2. using ip in tui: 2023-02-23_203735 2023-02-23_203746
  3. using hostname in cli: 2023-02-23_204525 2023-02-23_204532
  4. using ip in cli: 2023-02-23_204604 2023-02-23_204624

(I have also replaced the %h in the ssh config with real IP, which did not work either.)

All these approaches failed, so ... what is the correct way?

Environment

veeso commented 1 year ago

Hi,

patterns like %h are currently not supported in ssh2-config, so that won't work for sure atm.

The host syntax is not working, maybe there is an issue with comments after the host definition. I need to check if there is a bug in ssh2-config.

In case that won't work I'll may ask you to provide me with the debug log file generated by termscp.

veeso commented 1 year ago

It doesn't look like an issue with ssh2-config.

Could you try to run termscp with -D option and provide me with the log file (obfuscated at your discretion)? The log file can be found at:

$HOME/.config/termscp/termscp.log on Linux/BSD
$HOME/Library/Application Support/termscp/termscp.log on MacOs
FOLDERID_RoamingAppData\termscp\termscp.log on Windows
namespaceYcZ commented 1 year ago

It doesn't look like an issue with ssh2-config.

Could you try to run termscp with -D option and provide me with the log file (obfuscated at your discretion)? The log file can be found at:

$HOME/.config/termscp/termscp.log on Linux/BSD
$HOME/Library/Application Support/termscp/termscp.log on MacOs
FOLDERID_RoamingAppData\termscp\termscp.log on Windows

I changed my virtual machines and ssh config to the following for convenience: 2023-02-27_213337

ssh to test-ubuntu: 2023-02-27_213402

then run termscp with -D option: 2023-02-27_213440 2023-02-27_213502 then I found something wrong in the log file: termscp tried to connect to the test-ubuntu with my Windows username, not the cross specified in the ssh config file: 2023-02-27_215256 termscp log created by termscp -D test-ubuntu

so I tried again with username like this: 2023-02-27_214126 2023-02-27_214150 termscp used cross correctly this time, but still failed with an unknown error: image termscp log created by termscp -D cross@test-ubuntu

veeso commented 1 year ago

It looks like the ssh config resolves correctly and RSA key is actually found, but for some reason, the ssh crate reports an unknown error when authenticating. A last try could be to insert the private ssh key in the termscp key storage (CTRL+C, ssh keys) and see if anything changes, but I don't think so.

I'll investigate on some issues with RSA auth with ssh crate.

namespaceYcZ commented 1 year ago

It looks like the ssh config resolves correctly and RSA key is actually found, but for some reason, the ssh crate reports an unknown error when authenticating. A last try could be to insert the private ssh key in the termscp key storage (CTRL+C, ssh keys) and see if anything changes, but I don't think so.

I'll investigate on some issues with RSA auth with ssh crate.

I tried to insert the private ssh key (from id_rsa in my ~/.ssh/ directory) in the termscp key storage, but failed. (

  1. press Ctrl+N in SSH keys tab
  2. enter ip address and username
  3. termscp open my editor hx
  4. paste my private key into it, save and quit.
  5. termscp said ssh key is empty

) 2023-02-28_205819

But ... termscp did create a ssh key file named cross@192.168.0.106.key in %appdata%/termscp/.ssh. So I tried termscp -D cross@192.168.0.106 ... and failed again: termscp.log

veeso commented 1 year ago

I don't know hx as editor, maybe it's running on another thread after start. I'd say try with nano or vim

namespaceYcZ commented 1 year ago

I don't know hx as editor, maybe it's running on another thread after start. I'd say try with nano or vim

I tried again and this problem just disappeared. Both hx and nvim work. I don't know why but ... just let's forget this little interlude. I installed termscp on my ubuntu virtual machine and tried to connect to other linux virtual machine. I failed again and found a new problem: 2023-03-01_202526 (I need the PubkeyAcceptedKeyTypes field to bypass the restriction of the new version of the ssh client) termscp.log

veeso commented 1 year ago

Can you try temporarily to remove that field to see whether termscp works? Unfortunately, that field will be parsed correctly only in the 0.11.1 version.

namespaceYcZ commented 1 year ago

Can you try temporarily to remove that field to see whether termscp works? Unfortunately, that field will be parsed correctly only in the 0.11.1 version.

I tried again. The good news is that termscp can connect to my test server with specified username(termscp testuser@prod-rhel). The bad news is that termscp fails to connect to the remote server without a specified username if the local username is not the same as the remote username. It seems that termscp ignores the User field in the ssh config file and uses local username.

Video_2023-03-04_092744.webm tscp-failed.log tscp-success.log

(Termscp logs in Windows are here. I think this problem may be Windows-specific. )

namespaceYcZ commented 1 year ago

I tried again. The good news is that termscp can connect to my test server with specified username(termscp testuser@prod-rhel). The bad news is that termscp fails to connect to the remote server without a specified username if the local username is not the same as the remote username. It seems that termscp ignores the User field in the ssh config file and uses local username.

I have a couple of suggestions, although I don't know if they are appropriate. The first is to not show the Password: prompt when logging in successfully with the ssh key, just like the ssh tool does. Another is to put the termscp.log file in the cache directory instead of the config directory (if the project uses dirs crate, dirs::cache_dir() can be used , the cache directory is ~/.cache on Linux and ~\AppData\Local on Windows)

veeso commented 1 year ago

I fixed in 0.12 the issue with the username not being taken from the ssh config.

xd-mau5 commented 1 year ago

Hi, i just wanna say i'm still having this error with ssh config, even if i put the key into the key storage image

2023-05-17T16:47:10.5847296Z [DEBUG] (1) remotefs_ssh::ssh::sftp: Initializing SFTP connection...
2023-05-17T16:47:10.5851739Z [TRACE] (1) remotefs_ssh::ssh::config: [C:\Users\chris\.cargo\registry\src\github.com-1ecc6299db9ec823\remotefs-ssh-0.2.0\src\ssh\config.rs:69] Parsing configuration at C:\Users\elect/.ssh/config
2023-05-17T16:47:10.5858239Z [DEBUG] (1) remotefs_ssh::ssh::commons: Connecting to 'host:22'
2023-05-17T16:47:10.5860396Z [TRACE] (1) remotefs_ssh::ssh::commons: [C:\Users\chris\.cargo\registry\src\github.com-1ecc6299db9ec823\remotefs-ssh-0.2.0\src\ssh\commons.rs:59] Trying to connect to socket address 'host:22' (timeout: 30s)
2023-05-17T16:47:10.6678685Z [DEBUG] (1) remotefs_ssh::ssh::commons: Connection established with address host:22
2023-05-17T16:47:10.6681453Z [TRACE] (1) remotefs_ssh::ssh::commons: [C:\Users\chris\.cargo\registry\src\github.com-1ecc6299db9ec823\remotefs-ssh-0.2.0\src\ssh\commons.rs:136] Configuring algorithm preferences...
2023-05-17T16:47:10.6682625Z [TRACE] (1) remotefs_ssh::ssh::commons: [C:\Users\chris\.cargo\registry\src\github.com-1ecc6299db9ec823\remotefs-ssh-0.2.0\src\ssh\commons.rs:138] compression: true
2023-05-17T16:47:11.2726594Z [DEBUG] (1) remotefs_ssh::ssh::commons: Authenticating with username 'root' and RSA key
2023-05-17T16:47:11.2727606Z [TRACE] (1) remotefs_ssh::ssh::commons: [C:\Users\chris\.cargo\registry\src\github.com-1ecc6299db9ec823\remotefs-ssh-0.2.0\src\ssh\commons.rs:209] Trying to authenticate with RSA key at 'C:\Users\elect\AppData\Roaming\termscp/.ssh/root@oracle.key'
2023-05-17T16:47:11.2730528Z [ERROR] Authentication failed: [Session(-1)] unknown error
2023-05-17T16:47:11.2732057Z [TRACE] (1) remotefs_ssh::ssh::commons: [C:\Users\chris\.cargo\registry\src\github.com-1ecc6299db9ec823\remotefs-ssh-0.2.0\src\ssh\commons.rs:209] Trying to authenticate with RSA key at 'C:\Users\elect/.ssh/id_rsa'
2023-05-17T16:47:11.2734354Z [ERROR] Authentication failed: [Session(-1)] unknown error