Shared server guidance · Question & answer

How do I use SSH key paths that contain spaces on Windows?

Quote the entire key-file path so that spaces remain part of one argument. CMD and PowerShell expand environment variables differently, even though the SSH options themselves are the same.

BeginnerWindows 11 with Microsoft OpenSSH Client; Windows PowerShell 5.1 or PowerShell 7 as labelledLinux VPS and dedicated servers where a remote Linux command is shown
Go to the answer

Instructions

1. Verify the exact file in PowerShell

The identity file is the private key without the .pub suffix. Check its existence without printing its contents.

Local Windows PowerShell
Test-Path -LiteralPath "$env:USERPROFILE\.ssh\server key"

True confirms a file or directory exists at the literal path; confirm that your intended key is a file.

2. Connect using the correct shell syntax

Replace the sample filename with your existing private key. Do not copy a key from an unknown source.

Local Windows PowerShell
ssh -o IdentitiesOnly=yes -i "$env:USERPROFILE\.ssh\server key" adminuser@203.0.113.10

PowerShell expands $env:USERPROFILE inside double quotes.

Local Windows CMD
ssh -o IdentitiesOnly=yes -i "%USERPROFILE%\.ssh\server key" adminuser@203.0.113.10

CMD expands %USERPROFILE%. The quotes keep the complete path together.

3. Keep remote arguments separate

A local key path is interpreted by Windows. A path following a remote file-transfer destination is interpreted in the server context. If nested quoting becomes complex, connect interactively and run the remote command there.

Check the result

  • SSH does not report that the identity file is inaccessible.
  • The login uses the intended account and key.

Troubleshooting

PowerShell treats %USERPROFILE% as text
Use its $env:USERPROFILE syntax instead.
Permission denied still appears
A valid local path does not mean the server accepts that public key for the selected account. Check authentication separately.

Official references

Use the documentation for your installed version when a flag, service name or platform feature differs.