How to fix scp: No such file or directory in SSH

SSHINTERMEDIATEMEDIUMUpdated Jan 4, 2026ยท 294 views

This error occurs when scp cannot locate the file or directory you're trying to transfer. Common causes include incorrect file paths, typos, relative path confusion, or the file not existing at the specified location.

Quick fix

Fixes scp: No such file or directory

# For local files
ls -la /path/to/your/file.txt

# For remote files, SSH in first
ssh user@host
ls -la /path/to/your/file.txt
  1. Verify the source file exists using ls
  2. Use absolute paths instead of relative paths
  3. Quote paths with spaces or special characters
  4. Verify the destination directory exists and is writable
ssh โ€” error
# For local files
ls -la /path/to/your/file.txt
# For remote files, SSH in first
ssh user@host
ls -la /path/to/your/file.txt
scp: No such file or directory

What this error means

The 'scp: No such file or directory' error means the source file or destination directory cannot be found on the system where the transfer is being initiated. When using scp to copy a file locally to a remote server (scp localfile user@host:/path), scp looks for 'localfile' on your local machine. When copying from remote (scp user@host:/path /local), scp looks for the file on the remote server. If the path is wrong, contains typos, uses unexpanded shell variables, or the file doesn't exist, scp cannot proceed and displays this error.

Typical symptoms

  • scp command exits immediately with 'No such file or directory' message
  • File transfer fails before any connection attempt is made
  • Error occurs even though you believe the file exists
  • Works with some files but fails with others in the same directory
  • Transfer works on one machine but fails on another

Common causes

  1. File path contains typos or incorrect spelling of filename or directory
  2. Using relative paths that don't resolve to the expected location
  3. File or directory doesn't exist at the specified location
  4. Shell variables (like $HOME or $WORK) are not being expanded by the remote shell
  5. File is in a different directory than expected due to changed working directory
  6. File permissions prevent reading the file, causing scp to report it as missing
  7. Spaces or special characters in the path are not properly quoted or escaped

How to fix "scp: No such file or directory"

1Verify the source file exists using ls

First, check if the file actually exists at the path you're trying to transfer:

bash
# For local files
ls -la /path/to/your/file.txt

# For remote files, SSH in first
ssh user@host
ls -la /path/to/your/file.txt

If the file is not listed, verify the correct path.

2Use absolute paths instead of relative paths

Replace relative paths with absolute paths to avoid ambiguity about the current working directory:

bash
# Avoid this (relative path)
scp myfile.txt user@host:uploads/

# Use this instead (absolute path)
scp /home/user/myfile.txt user@host:/home/user/uploads/

Absolute paths start with / and don't depend on which directory your terminal is currently in.

3Quote paths with spaces or special characters

If your file path contains spaces or special characters, wrap it in quotes:

bash
# This will fail if 'my file.txt' has a space
scp my file.txt user@host:/remote/path/

# Quote the path to preserve spaces
scp "my file.txt" user@host:/remote/path/

# For paths with special characters
scp "/path/with/$variables/file.txt" user@host:/remote/path/
4Verify the destination directory exists and is writable

Ensure the destination directory exists on the target system and you have write permissions:

bash
# SSH into the remote host
ssh user@host

# Check if directory exists
ls -ld /remote/destination/path/

# Create it if it doesn't exist
mkdir -p /remote/destination/path/

# Verify write permissions
touch /remote/destination/path/test.txt && rm /remote/destination/path/test.txt
5Use verbose mode to debug the exact error

Add the -v flag to see detailed output about where scp is looking for the file:

bash
scp -v /local/file.txt user@host:/remote/path/

The verbose output will show:
- Exact paths being checked
- Connection attempts
- Where the error occurs
- Directory listings as scp tries to locate files

This often reveals typos or path issues you might have missed.

6Check for shell variable expansion issues

If you're using environment variables in the remote path, ensure they're properly handled:

bash
# This may NOT expand $HOME on the remote system
scp localfile user@host:$HOME/uploads/

# Use literal path instead
scp localfile user@host:/home/username/uploads/

# Or use -O flag to enable OpenSSH's path globbing
scp -O localfile user@host:~/uploads/

When you specify a remote path with a variable like $HOME, the local shell may not expand it before sending to the remote system.

7Verify you have read permissions on the source file

Check that you can read the source file. Missing read permissions can cause scp to report the file as not found:

bash
# Check permissions
ls -l /path/to/file.txt

# If you don't have read permission, add it
chmod +r /path/to/file.txt

# Test that you can read it
cat /path/to/file.txt

Advanced notes

On some systems, scp may behave differently when you're logged into a server and trying to reference local files. If you run scp while SSH'd into a remote system, the local file path may be interpreted as a remote path on the current system. To avoid this, always run scp from your local machine, not from within an SSH session. For Windows OpenSSH users, path handling can be problematic. Using absolute paths and proper quoting usually resolves these issues. Some systems support the -O flag (use OpenSSH protocol) or -S flag (specify ssh program) for additional control over path handling and globbing behavior. The error 'realpath: No such file' is related but indicates path canonicalization failure when dealing with directory transfers.

Frequently asked questions

What does "scp: No such file or directory" mean?
The 'scp: No such file or directory' error means the source file or destination directory cannot be found on the system where the transfer is being initiated. When using scp to copy a file locally to a remote server (scp localfile user@host:/path), scp looks for 'localfile' on your local machine. When copying from remote (scp user@host:/path /local), scp looks for the file on the remote server.
How do I fix "scp: No such file or directory"?
This error occurs when scp cannot locate the file or directory you're trying to transfer. Common causes include incorrect file paths, typos, relative path confusion, or the file not existing at the specified location.
What causes "scp: No such file or directory"?
File path contains typos or incorrect spelling of filename or directory Using relative paths that don't resolve to the expected location File or directory doesn't exist at the specified location
Is the "scp: No such file or directory" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading