GICT knowledge base
Use scp on Linux: SSH Ports, Keys and Safe File Copies
Published
The OpenSSH scp command copies files over SSH authentication and transport. Since OpenSSH 9.0 it uses SFTP by default; its historical name does not mean current versions necessarily use the legacy SCP protocol. A server offering FTP alone cannot accept an scp transfer.
Check access and the server identity
Obtain the correct host, SSH port, account, authorized key and permitted directory. Verify a new host-key fingerprint through a trusted separate channel. Stop on an unexpected key change; do not bypass strict checking. Use a transfer account rather than root, and preserve a recovery copy before overwriting a remote file.
Upload and download syntax
These are templates, not connections to a real service. Replace the example host, user and paths only after confirming authorization. Capital -P selects the port; lowercase -p preserves modification/access times and file mode bits.
scp -P 2222 -i ~/.ssh/transfer_ed25519 ./report.txt user@server.example:/upload/report.txt
scp -P 2222 -i ~/.ssh/transfer_ed25519 user@server.example:/upload/report.txt ./downloaded-report.txt
The source comes before the destination. A local name containing a colon can be mistaken for a remote specification; use an explicit local path such as ./name:part. Quote local paths containing spaces and check the installed client’s remote path handling; old SCP and modern SFTP modes have different shell-expansion behavior.
Common options
| Option | Meaning and boundary |
|---|---|
| -r | Copy a directory recursively. OpenSSH scp follows symlinks encountered during traversal, so inspect scope before copying a tree. |
| -p | Preserve times and mode bits where permitted; not a complete ownership/ACL backup. |
| -i path | Select an identity file. Keep the private key protected; never upload it into the destination web root. |
| -F path | Use a specified SSH client configuration file. |
| -l limit | Limit bandwidth in kilobits per second, not kilobytes. |
| -4 or -6 | Restrict address family when the destination supports it. |
| -v | Show diagnostics; redact account and infrastructure details before sharing. |
-O requests the legacy SCP protocol. It is a compatibility option, not a general security or login-error fix. Do not use it simply to silence a path or subsystem problem without understanding the server requirements.
Verify the result
Check the exit status and compare important file contents or trusted checksums. A progress meter does not prove application-level correctness, and recursive copying does not create a consistent database snapshot or a versioned backup. For multiple operations and directory inspection, use the interactive SFTP client.
Reference: OpenSSH scp manual.
Reviewed October 15, 2026. The port and identity syntax was tested against a disposable loopback SSH service with synthetic files; these example hostnames were not contacted.
Related guides
How to Restrict an SSH Key to One Command
Restrict an SSH key to one command with authorized_keys options. Protect the command and check that unwanted shell and forwarding access are denied.
Linux and CommandsSelf-Hosted Video Processing With FFmpeg: A Practical Guide
Learn how to self-host video processing on a VPS using FFmpeg, with practical commands for conversion, compression, thumbnails, and automated workflows.
Linux and CommandsHow to use nohup: Commands in Linux That Survive Terminal Closes
Keep commands running after you close the terminal. nohup examples with wget, Python, rsync, and Docker on any VPS.
Linux and CommandsHow to Fix “Too Many Open Files” Error on Linux Servers
Learn how to fix the "Too Many Open Files" error on Linux servers by understanding file descriptors, adjusting limits, and diagnosing leaks effectively.
