# Fix Vim Netrw Not Opening Remote SCP SSH Directories

You try to browse a remote directory using Vim's built-in Netrw file explorer:

vim
:e scp://user@remote-server:/var/www/

But instead of showing the directory listing, you get:

bash
netrw is unable to list the files in this directory

Or:

bash
Permission denied (publickey,password).
netrw: scp command failed

Netrw uses SCP/SFTP to access remote directories, and any authentication or configuration issue breaks the connection.

Step 1: Test SSH Connectivity

Before debugging Netrw, verify SSH works from the command line:

bash
ssh user@remote-server ls /var/www/

If this fails, the issue is with SSH, not Netrw. Fix SSH first:

bash
# Test with verbose output
ssh -v user@remote-server ls /var/www/

Common SSH issues: - Wrong username or hostname - SSH key not added to ~/.ssh/authorized_keys on the remote server - SSH agent not running locally - Non-standard SSH port

Step 2: Non-Standard SSH Port

If the remote server uses a non-standard SSH port (not 22), specify it in the Netrw URL:

vim
:e scp://user@remote-server:2222/var/www/

Or configure it in SSH config (~/.ssh/config):

bash
Host remote-server
    HostName remote-server.example.com
    User user
    Port 2222
    IdentityFile ~/.ssh/id_remote

Then the Netrw command is simpler:

vim
:e scp://remote-server:/var/www/

Netrw uses the SSH configuration automatically.

Step 3: SSH Key Authentication

If the remote server requires key-based authentication, ensure your SSH agent has the key:

bash
ssh-add -l
ssh-add ~/.ssh/id_remote

Test that the key works:

bash
ssh -i ~/.ssh/id_remote user@remote-server echo "connected"

For headless servers without an SSH agent, you can configure Netrw to use a specific identity file by setting the g:netrw_scp_cmd variable:

vim
let g:netrw_scp_cmd = 'scp -i ~/.ssh/id_remote'

Step 4: Netrw Protocol Choice

Netrw supports multiple protocols for remote file access:

```vim " SCP protocol :e scp://user@host:/path/

" SFTP protocol (often more reliable) :e sftp://user@host:/path/

" SSH with rsync :e rsync://user@host:/path/ ```

If SCP fails, try SFTP. SFTP uses a different subsystem and may work when SCP does not:

vim
:e sftp://user@remote-server:/var/www/

Step 5: Netrw Browsing Options

Once connected, Netrw provides a file browser interface. Key commands:

  • <Enter> -- Open file or enter directory
  • - -- Go up one directory
  • D -- Delete file/directory
  • R -- Rename file/directory
  • d -- Create new directory
  • gh -- Toggle hidden files
  • i -- Cycle listing style (thin, long, wide, tree)
  • s -- Sort by name/time/size

Step 6: Netrw Configuration

Configure Netrw for better remote access experience:

```vim " Use SFTP instead of SCP (more reliable) let g:netrw_scp_cmd = 'sftp'

" Keep remote connection alive longer let g:netrw_sftp_cmd = 'sftp -o ServerAliveInterval=30'

" Enable transparent editing (auto-upload on save) let g:netrw_keepdir = 0

" Use a specific SSH key let g:netrw_scp_cmd = 'scp -i ~/.ssh/deploy_key' ```

Step 7: Debugging Netrw Failures

Enable Netrw debugging:

vim
let g:netrw_debug = 1

Then try the remote connection again. Netrw writes debug output to netrwDebug.vim in your current directory. Check it for the exact SCP/SFTP command that failed.

You can also manually run the command Netrw uses:

bash
# Netrw typically runs something like:
scp -q -l user@remote-server:/var/www/

Run this manually to see the actual error message.

Step 8: Alternative: Use SSHFS

For frequent remote editing, consider mounting the remote filesystem with SSHFS:

bash
sudo apt install sshfs
mkdir -p ~/remote
sshfs user@remote-server:/var/www ~/remote

Then edit normally:

vim
:e ~/remote/index.html

This provides better performance and reliability than Netrw for interactive editing, because all file operations use the local filesystem API.

Unmount when done:

bash
fusermount -u ~/remote