2

server A (1.2.3.4): I'm accessing it every day, no issues:

  • keys on the local machine are in ~/.ssh (id_rsa and id_rsa.pub)

  • user "toraritte" is available on both machines

  • starting and using Vim the following way:

    $ ssh-agent vim
    

    Inside Vim:

    :!ssh-add
    (enter pass-phrase => "identity added")
    
    :Lexplore scp://1.2.3.4//home/toraritte/
    

server B (5.6.7.8): just set up, scp & ssh works both outside and inside Vim, but :Lexplore scp:// fails with shell returned 255. The setup is different too, but can't figure out the problem:

  • Users are different (toraritte on local, myadmin on remote)

  • Using a .pem file to which is not in the ~/.ssh folder like so:

    # similar with scp
    ssh -i my.pem [email protected]
    

Starting and using Vim:

$ ssh-agent vim

Inside Vim:

:!ssh-add my.pem
(no passphrase => "identity added")

Testing the shell:

:term

# on the terminal:
$ ssh [email protected]                         #=> works
$ scp [email protected]:/home/myadmin/test_file . #=> works

but

:Lexplore scp://[email protected]//home/myadmin/

fails with shell returned 255, which can mean a lot of things.

So how can I troubleshoot this further?


workaround: Started using Midnight Commander to access the remote machine's files for the time being, and use Vim as an external editor.


update: Thank you @MartinTournoij for constantly providing new tips!

  1. Does using sftp:// work?

    No. This time there are no errors, only an empty side panel opens up.

  2. You can try adding -v to g:netrw_sftp_cmd and/or g:netrw_scp_cmd and see if that shows anything; you can add it multiple times for more information

    This didn't work either. The only difference is that on the command line is now

    shell returned 255
    
    
    shell returned 255
    Press ENTER or type command to continue
    

    and the second shell returned 255 will take longer to appear. I presume the output is more verbose, but it is not presented in Vim...

  3. Also noticed this bug: Vim issue #11346 – not sure if it's related, but it might be?

    The scp/sftp operations in the issue certainly seem to be the same, but the error there is 1, so not sure either. Thank you for digging this up though! I will keep watching it for updates.

4
  • Does using sftp:// work? scp and sftp use different protocols, and some defaults/settings changed last year. I think I've seen people have problems with this before. Oct 11, 2022 at 18:17
  • Appreciate the tip, but sftp:// isn't working either. It doesn't throw any errors, but simply opens an empty side window.
    – toraritte
    Oct 11, 2022 at 20:49
  • You can try adding -v to g:netrw_sftp_cmd and/or g:netrw_scp_cmd and see if that shows anything; you can add it multiple times for more information. Not sure if netrw displays that nicely though. Oct 13, 2022 at 0:26
  • Also noticed this bug: github.com/vim/vim/issues/11346 – not sure if it's related, but it might be? Oct 13, 2022 at 0:27

1 Answer 1

1

Curiously, the solution was almost the same as the one for Midnight Commander explained in this article:

In Midnight Commander, unlike in SSH or SCP, you cannot pass the identity file with the -i parameter for public key authentication. Thus, you have to store the SSH configuration in your config file. The file is located in your home directory in ~/.ssh/config.

If the file does not exist, you can just edit with the nano editor and then make sure that only your user has access to it:

chmod 600 config

The config file should contain the location of your private SSH key, the corresponding username, and the hostname. In addition, you can configure the port and the alias you want to use to save some typing (Host command).

Host yourHost
    HostName 10.0.0.1
    Port 2222
    User ubuntu
    IdentityFile ~/.ssh/privatekey.key

To follow the article's example values, this is the command that kept failing for me,

:Lexplore scp://[email protected]:2222//home/ubuntu/

and I just needed to replace the user@host:port part with the Host section's value in the ~/ssh.config

:Lexplore scp://yourHost//home/ubuntu/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.