Skip to main content

Common Errors

This page covers the most common SCP errors, their root causes, and step-by-step fixes.

1. Permission Denied (publickey)

Error:

Permission denied (publickey).
lost connection

Cause: The remote server does not have your public key, or the key file permissions are wrong.

Fix:

# 1. Ensure your key exists
ls -la ~/.ssh/id_ed25519.pub

# 2. Copy your key to the remote server
ssh-copy-id user@server

# 3. Fix key file permissions if needed
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub

# 4. Test SSH access
ssh user@server "echo 'Access OK'"

2. Permission Denied (password)

Error:

user@server's password:
Permission denied, please try again.

Cause: Wrong password, or password authentication is disabled on the server.

Fix:

# Check if password auth is enabled on the server
ssh user@server -o PreferredAuthentications=password -o PubkeyAuthentication=no

# If disabled, use SSH keys instead (see Section 1: Installation and Setup)

3. Connection Refused

Error:

ssh: connect to host 192.168.1.100 port 22: Connection refused
lost connection

Cause: SSH daemon is not running, or the port is wrong.

Fix:

# On the remote server, check SSH status
sudo systemctl status sshd

# Start SSH if not running
sudo systemctl start sshd

# If using a non-standard port, specify it
scp -P 2222 ./file.txt user@server:/path/

4. Connection Timed Out

Error:

ssh: connect to host 203.0.113.50 port 22: Connection timed out
lost connection

Cause: Firewall blocking the port, wrong IP address, or server is down.

Fix:

# 1. Verify the host is reachable
ping -c 3 203.0.113.50

# 2. Check if the SSH port is open
nc -zv 203.0.113.50 22

# 3. Check your firewall rules (on server)
sudo ufw status
sudo iptables -L -n | grep 22

5. Host Key Verification Failed

Error:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Host key verification failed.
lost connection

Cause: The server's SSH host key changed (reinstalled OS, different server on same IP).

Fix:

# Remove the old host key
ssh-keygen -R 192.168.1.100

# Reconnect — you'll be prompted to accept the new key
ssh user@192.168.1.100
Security Check

Before removing a host key, confirm that the server was actually reinstalled or re-IP'd. A changed host key can indicate a man-in-the-middle attack.

6. No Such File or Directory

Error:

scp: /opt/data/export.csv: No such file or directory

Cause: The source file path is wrong, or the file does not exist on the remote server.

Fix:

# Verify the file exists on the remote server
ssh user@server "ls -la /opt/data/export.csv"

# Check for typos in the path
ssh user@server "find /opt/data -name 'export*'"

7. Not a Regular File

Error:

scp: /opt/data/: not a regular file

Cause: You are trying to copy a directory without the -r flag.

Fix:

# Add -r for directories
scp -r user@server:/opt/data/ ./local-data/

8. Broken Pipe

Error:

client_loop: send disconnect: Broken pipe
lost connection

Cause: Network instability, SSH session timeout, or the remote server dropped the connection.

Fix:

~/.ssh/config
# Add keep-alive settings
Host *
ServerAliveInterval 60
ServerAliveCountMax 3
TCPKeepAlive yes

9. Disk Quota Exceeded

Error:

scp: /home/user/backup.tar.gz: Disk quota exceeded
lost connection

Cause: The remote user has exceeded their disk quota.

Fix:

# Check disk usage on remote
ssh user@server "df -h"
ssh user@server "du -sh ~/*"

# Clean up or choose a different destination
scp ./backup.tar.gz user@server:/tmp/

Quick Diagnosis Workflow

flowchart TD
A[SCP Error] --> B{Can you SSH?}
B -->|No| C{Connection refused?}
C -->|Yes| D[Check sshd status and port]
C -->|No| E{Timed out?}
E -->|Yes| F[Check firewall and IP]
E -->|No| G[Check key permissions]
B -->|Yes| H{File exists?}
H -->|No| I[Verify path on remote]
H -->|Yes| J{Is it a directory?}
J -->|Yes| K[Add -r flag]
J -->|No| L[Check disk space and permissions]

What's Next?

Need a quick reference? Check the SCP Cheatsheet.