Shared server guidance · Question & answer

How do I use a custom SSH port and key with SCP or SFTP?

SCP and SFTP use uppercase -P for the server port, while ssh uses lowercase -p. Both can select a private key with -i and apply IdentitiesOnly=yes. These client options must match the server’s existing configuration.

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. Check the existing connection settings

Confirm the assigned port and account. If you have a tested SSH Host alias, it can carry the same settings for transfers.

2. Upload with SCP using explicit settings

Use a writable destination and an unused target filename.

Local Windows PowerShell
scp -P 2222 -o IdentitiesOnly=yes -i "$env:USERPROFILE\.ssh\server_ed25519" ".\report.txt" adminuser@203.0.113.10:report-upload.txt

Uppercase -P chooses port 2222. Lowercase -p in SCP has a different purpose: preserving file attributes.

3. Open SFTP using the same endpoint

SFTP starts an interactive file-transfer prompt after authentication.

Local Windows PowerShell
sftp -P 2222 -o IdentitiesOnly=yes -i "$env:USERPROFILE\.ssh\server_ed25519" adminuser@203.0.113.10

At the SFTP prompt, use pwd and lpwd to distinguish remote and local working directories.

Check the result

  • The transfer reaches the expected verified server on its assigned port.
  • The selected identity authenticates and the intended file-transfer operation succeeds.

Troubleshooting

SCP still tries port 22
Check that uppercase -P was used before source and destination.
SSH works through an alias but the transfer fails
Use that same alias or compare its effective user, port and identity settings.

Official references

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