Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Use scp when you need to copy files between an Ubuntu computer and a reachable SSH server. Install the OpenSSH client, authenticate to the remote account, and run scp source target. A remote location uses the form [user@]host:path; putting the remote location first downloads a file, while putting it second uploads one.

On current OpenSSH releases, including Ubuntu installations using OpenSSH 9.0 or newer, scp uses the SFTP protocol by default. The legacy SCP/rcp protocol remains available with -O for compatibility, but it should not be your routine setting. This guide shows the exact commands, key authentication, directory transfers, port and identity options, protocol differences, and safe troubleshooting.

What SCP on Ubuntu does

scp is the OpenSSH secure file-copy command. It transfers data through an SSH connection, so the remote computer must run an SSH server, accept connections from your Ubuntu machine, and authenticate your account. Ubuntu’s documentation describes the server daemon, sshd, as handling those client connections; the file transfer begins after authentication. Network reachability, firewall rules, the listening port, and the server’s account permissions still determine whether a transfer can work.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The command itself is included in the OpenSSH client software. It is not a separate commercial product and does not require a special hardware accessory.

#1 Best Overall
Sale
Lexar D40E 128GB Dual USB 3.2 Gen 1 Type-C Jump Drive, Champagne Silver | USB-C Flash, Metal Housing, Swivel Design, Thumb Drive
  • USB-C 2-in-1 storage OTG: The Lexar JumpDrive Dual Drive D40E features USB Type-A and Type-C connectors in a slim, portable form factor for easy device compatibility
  • Transfer speeds up to 100MB/s: Based on internal testing, performance may vary depending upon the host device, interface, and usage conditions. 1MB=1,000,000 bytes
  • Plug and Play: Widely compatible with USB Type-C smartphones, tablets, laptops, Macs, and traditional Type-A devices, no software installation required. The 360° swivel design allows for easy switching between connectors without the hassle of losing a cap
  • Durable & Compact: The Lexar D40E USB memory stick features a metal enclosure, withstands temperatures from 0° to 50° C (32°F to 122°F), and is lightweight at 26g with dimensions of 70.4 x 16.9 x 11.7mm
  • Security & Warranty: Securely protects files using an advanced security software solution with 256-bit AES encryption. Backed by a Lexar 3-year limited warranty

Install the required OpenSSH packages

Install the client on the Ubuntu computer that runs SCP

Open a terminal and install the client package:

sudo apt install openssh-client

You need this package on the machine from which you type the scp command. If it is already installed, APT reports that the newest version is present.

Install the server on an Ubuntu destination

An Ubuntu computer that must accept incoming transfers needs the server package:

sudo apt install openssh-server

The remote host also needs a reachable SSH service and an account that can log in. Installation alone does not guarantee reachability: a firewall, cloud security rule, routing problem, stopped service, or nonstandard port can still block the connection. Canonical’s OpenSSH server documentation covers server setup and administration.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand SCP’s source-and-target syntax

The general form is:

scp [options] source target

A remote source or target is written as:

[user@]host:path

The endpoint without a host name is local. Therefore, direction is determined by position:

Task Command shape What happens
Upload from Ubuntu to a server scp local-file user@host:/remote/path/ The local file is the source; the remote path is the destination.
Download from a server to Ubuntu scp user@host:/remote/file /local/path/ The remote file is the source; the local path is the destination.

Use an absolute remote path when you want an unambiguous destination, such as /home/alice/. A path ending in / indicates a directory. If the destination directory does not exist or your account cannot write there, the transfer fails after connection and authentication.

If a local filename contains a colon, use an explicit relative or absolute path so scp does not mistake the colon for the separator in a host specification. For example, use ./notes:2026.txt rather than passing an ambiguous bare name.

Copy a single file

Upload a local file

This example sends report.txt from the current Ubuntu directory to Alice’s home directory on example.net:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
SANDISK 128GB Ultra Flair, USB-A Flash Drive, Up to 150MB/s Read Speeds | USB Flash Drive, Up to 15x Faster than standard 2.0, Password Protection, Durable, Sleek Metal Casing, USB 3.0, Silver/Black
  • High-speed USB 3.0 performance of up to 150MB/s(1) [(1) Write to drive up to 15x faster than standard USB 2.0 drives (4MB/s); varies by drive capacity. Up to 150MB/s read speed. USB 3.0 port required. Based on internal testing; performance may be lower depending on host device, usage conditions, and other factors; 1MB=1,000,000 bytes]
  • Transfer a full-length movie in less than 30 seconds(2) [(2) Based on 1.2GB MPEG-4 video transfer with USB 3.0 host device. Results may vary based on host device, file attributes and other factors]
  • Transfer to drive up to 15 times faster than standard USB 2.0 drives(1)
  • Sleek, durable metal casing
  • Easy-to-use password protection for your private files(3) [(3)Password protection uses 128-bit AES encryption and is supported by Windows 7, Windows 8, Windows 10, and Mac OS X v10.9 plus; Software download required for Mac, visit the SanDisk SecureAccess support page]
scp report.txt alice@example.net:/home/alice/

You will be prompted for Alice’s SSH password unless another authentication method, such as a key, is already configured. The destination file normally keeps the source filename, so this creates /home/alice/report.txt.

Download a remote file

Place the remote specification first to retrieve a file into the current local directory:

scp alice@example.net:/home/alice/report.txt .

The dot means “the current local directory.” You can instead choose a directory or a new filename, for example:

scp alice@example.net:/home/alice/report.txt ~/Downloads/report-copy.txt

Copy to a different remote filename

A destination path can include a new basename:

scp report.txt alice@example.net:/home/alice/archive/report-2026.txt

The remote account must be able to create or replace that file in the target directory. SCP does not elevate privileges on the server; a normal account cannot write to protected directories unless the server-side permissions or workflow explicitly allow it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Copy a directory recursively

Add uppercase -r when the source is a directory:

scp -r project/ alice@example.net:/home/alice/

This copies the directory and its contents below the remote home directory. To download a remote directory into the current local directory, reverse the endpoints:

scp -r alice@example.net:/home/alice/project/ .

Check the resulting path before starting a large transfer. A destination such as /home/alice/backup/ can result in /home/alice/backup/project/, while a destination naming an existing directory may place the source directory inside it. The Ubuntu Noble scp manual documents recursive copying and the complete option set.

Use a nonstandard SSH port or a specific key

Connect to a different port with uppercase -P

SSH servers commonly listen on port 22, but an administrator may configure another port. Use uppercase -P:

Rank #3
Sale
2 Pack 64GB USB Flash Drive USB 2.0 Thumb Drives Jump Drive Fold Storage Memory Stick Swivel Design - Black
  • What You Get - 2 pack 64GB genuine USB 2.0 flash drives, 12-month warranty and lifetime friendly customer service
  • Great for All Ages and Purposes – the thumb drives are suitable for storing digital data for school, business or daily usage. Apply to data storage of music, photos, movies and other files
  • Easy to Use - Plug and play USB memory stick, no need to install any software. Support Windows 7 / 8 / 10 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, compatible with USB 2.0 and 1.1 ports
  • Convenient Design - 360°metal swivel cap with matt surface and ring designed zip drive can protect USB connector, avoid to leave your fingerprint and easily attach to your key chain to avoid from losing and for easy carrying
  • Brand Yourself - Brand the flash drive with your company's name and provide company's overview, policies, etc. to the newly joined employees or your customers
scp -P 2222 report.txt alice@example.net:/home/alice/

Option capitalization matters. Lowercase -p does something else: it asks scp to preserve modification times, access times, and file modes from the source. It does not select a port.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Select an identity file with -i

If the account requires a particular private key, specify it with -i:

scp -i ~/.ssh/id_ed25519 report.txt alice@example.net:/home/alice/

The private key must be readable by your local user and should be protected from other users. If the key has a passphrase, SSH asks for it when needed. You can avoid repeating the full option by defining a host alias and identity in ~/.ssh/config; Ubuntu’s OpenSSH guidance discusses host-specific key configuration.

Set up SSH-key authentication

Keys are useful when you transfer regularly or need noninteractive authentication. The private key stays on the Ubuntu client; the corresponding public key is placed in the remote account’s authorized keys. A passphrase protects the private key if the client filesystem is exposed.

  1. Create an Ed25519 key pair. Run:
    ssh-keygen -t ed25519

    Accept the suggested location or enter another one, and choose a passphrase when prompted. The private key is normally stored under ~/.ssh; do not copy it to the server.

  2. Install the public key on the remote account. Run:
    ssh-copy-id alice@example.net

    The command asks for the account’s current password and appends the public key to the remote account’s authorized-key file.

  3. Test SSH before testing SCP. Run:
    ssh alice@example.net

    If an interactive SSH login fails, fix the host, port, account, key, or server configuration before diagnosing the file copy.

  4. Use the key for the transfer if necessary.
    scp -i ~/.ssh/id_ed25519 report.txt alice@example.net:/home/alice/

For a server using a custom port, include the same port in both the SSH test and the SCP command, for example ssh -p 2222 alice@example.net and scp -P 2222 .... SSH uses lowercase -p for its port option, whereas SCP uses uppercase -P; do not transfer the capitalization between commands.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Know which SCP protocol your client is using

OpenSSH 9.0, released on 2022-04-08, changed the default implementation: its release notes state, “This release switches scp(1) from using the legacy scp/rcp protocol to using the SFTP protocol by default.” Modern clients therefore retain the scp command interface while using SFTP for the transfer operation. Read the OpenSSH 9.0 release notes for the change announcement.

Mode How to select it Important behavior When it matters
Modern SFTP-backed mode Default on OpenSSH 9.0 and newer Uses SFTP semantics rather than remote-shell wildcard expansion. Use this for ordinary transfers when the server supports the required SFTP behavior.
Legacy SCP/rcp mode Add -O Uses the older protocol and expands remote wildcards through the remote shell. Compatibility with an older server or appliance that cannot handle the client’s SFTP-based operation.

Do not treat -O as a performance switch or a routine fix. It changes protocol behavior. In legacy mode, shell metacharacters and wildcards require careful quoting because expansion occurs on the remote shell. For example, a pattern intended for the remote host must be quoted so your local shell does not expand it first:

Rank #4
Sale
SIMMAX 32GB Memory Stick USB 2.0 Flash Drives Swivel Thumb Drive Pen Drive (32GB Purple)
  • GOOD VALUE PACKAGE - 1 Pack 32GB Memory Stick USB 2.0 Flash Drives with great cost performance and high quality.
  • BIG CAPACITY - The available capacity: 29.10GB-29.8GB, You can save the data of movies, music, photos, designs, programs, manuals, handouts in a high speed.Good performance in digital data storing, transferring and sharing with families, friends, workmates, clients and machines.
  • EASY TO USE & PLUG AND WORK - Support windows 7 / 8 / 10 / Vista / XP / 2000 / ME / NT Linux and Mac OS, Compatible with USB2.0 and below.
  • TWISTTURN DESIGN & EASY CARRY - The metal clip rotates 360° round the ABS plastic body which with rubber oil skin feeling finish. The capless design can avoid lossing of cap, and providing efficient protection to the USB port.
  • WARRANTY & SUPPORT - SIMMAX logo is laser printed on the USB connector surface, our products are of good quality and we promise that any problem about the product within one year since you buy.
scp -O 'alice@example.net:/home/alice/logs/*.gz' .

Exact wildcard behavior can vary with the remote shell and filenames. If a current client reports an SFTP-related protocol error, verify the actual server or appliance implementation before selecting legacy mode. The Noble manual documents current behavior, while the Ubuntu Jammy manual describes an older package generation whose default behavior may differ. SFTP support is not universal across every SSH server or embedded appliance.

Choose password or key authentication

Authentication method Best fit Advantages Things to manage
Password Occasional, interactive copies No key setup; works when the server permits password login. Requires a prompt for each connection and depends on the server’s password policy.
Ed25519 SSH key Frequent transfers, scripts, or multiple hosts Can avoid repeated account-password entry and can be selected per host. Protect the private key, use a passphrase, and keep the public key correctly installed on the remote account.

Authentication does not grant extra filesystem rights. After login, the remote account still needs read permission for a download, write permission for an upload, and directory traversal permission for every parent directory in the path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot a failed transfer

Work from the endpoint and authentication basics toward server diagnostics. Avoid changing security settings blindly.

1. Confirm the host, account, and path

  • Check the spelling of the host name and username.
  • Confirm that the remote path exists and is written for the remote operating system.
  • For a download, verify that the account can read the source file.
  • For an upload, verify that the destination directory exists and is writable.
  • Confirm whether the server uses port 22 or a custom port, and pass the correct value with uppercase -P.

2. Test the SSH connection separately

Run SSH with the same account and port before repeating the copy:

ssh -p 2222 alice@example.net

Omit -p 2222 when the server uses the default port. If SSH cannot establish a session, SCP cannot transfer the file. Resolve DNS, routing, firewall, service availability, or authentication first.

3. Turn on SCP’s verbose diagnostics

Add -v to see client-side connection, host-key, authentication, and transfer details:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
scp -v report.txt alice@example.net:/home/alice/

For a custom port or key, keep those options in the diagnostic command:

Best Value
IMEASON Swivel Design 16GB USB Flash Drive with Keychain, USB 2.0 Portable Thumb Drive Memory Stick, FAT32 Format Flashdrive for Data Storage, Photos, Music, Files (Black, 16 GB)
  • 【16GB Flash Drive】USB flash drives with 16GB capacity, meet your needs of daily use on work, school, home and travelling for photos, music, videos, files storage and transfer. IMEASON thumb drives can be used to store different files, easy to data backup.
  • 【Metal Swivel Cap Design】USB thumb drive is metal swivel cover provides extra protection for the usb thumbdrive connector, no usb drive cap to lose; keychain design makes it easier to carry without worrying lose it.
  • 【Wide Compatibility】USB drive supports Windows 7/8/10/11 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, also Supports USB 2.0 and 1.1 ports. USB Stick support TV, desktop, notebook computer, car, audio and other device. The USB Memory Stick is your great data storage and transfer companion with traveling and working.
  • 【Easy to use】usb memory stick is plug and play without any software installation. Just simply plug the Flashdrive into the port of your USB-compatible devices such as computer, laptop to start data storage or transmission.
  • 【What You Get】16 GB USB Flash Drive Thumb Drive, The default format of the usb storage flash drive is FAT32.
scp -v -P 2222 -i ~/.ssh/id_ed25519 report.txt alice@example.net:/home/alice/

A successful command returns status 0. A nonzero status indicates an error; the verbose output usually identifies the stage at which it occurred.

4. Inspect the remote SSH service when you administer it

On an Ubuntu server you control, follow the SSH service log while reproducing the failure:

sudo journalctl -fu ssh.service

Look for rejected users, invalid keys, denied authentication methods, connection limits, or subsystem errors. If you edit the server configuration, validate it before restarting:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo sshd -t

Only restart after the syntax check succeeds. A malformed configuration can lock administrators out. This server-side check is not a routine step on the client that merely runs scp.

5. Treat host-key warnings as security events

If SSH reports that a host key changed, do not disable host-key checking as a casual workaround. A legitimate server rebuild or key rotation is possible, but an unexpected change can indicate that you are connecting to the wrong host or that the connection is being intercepted. Verify the new fingerprint with the server owner or administrator, then update the local known-host entry through an approved process.

6. Investigate protocol compatibility

If authentication succeeds but the transfer fails with a subsystem or protocol complaint, determine the client OpenSSH version and the remote server’s SFTP support. On a modern client, try the normal command first. Use -O only when the administrator confirms that legacy SCP/rcp is required by that server. Do not assume that every device advertising SSH implements SFTP identically.

Security practices for routine SCP use

  • Verify the destination. A valid SSH login does not prove that the host is the intended system; confirm host keys and use a known hostname or verified address.
  • Prefer key authentication with a passphrase for recurring work, while keeping the private key on the client and restricting access to it.
  • Limit the remote account. Use an account with only the filesystem access required for the transfer rather than an administrator account.
  • Quote carefully. Spaces and shell metacharacters can be interpreted by a local shell, and legacy -O mode adds remote-shell expansion concerns. Quote paths deliberately and test unusual names with a small transfer.
  • Check permissions before using elevated access. SCP does not run a remote command through sudo to write protected files. Transfer to an account-owned directory, then use an approved server-side move procedure if necessary.
  • Do not expose secrets in shell history. SCP reads passwords interactively; never put a password directly into the command line.

Practical command reference

Purpose Command
Install client sudo apt install openssh-client
Install Ubuntu server sudo apt install openssh-server
Upload one file scp report.txt alice@example.net:/home/alice/
Download one file scp alice@example.net:/home/alice/report.txt .
Upload a directory scp -r project/ alice@example.net:/home/alice/
Use port 2222 scp -P 2222 report.txt alice@example.net:/home/alice/
Use a selected private key scp -i ~/.ssh/id_ed25519 report.txt alice@example.net:/home/alice/
Show diagnostics scp -v report.txt alice@example.net:/home/alice/
Select legacy SCP/rcp protocol scp -O report.txt alice@example.net:/home/alice/
Generate an Ed25519 key ssh-keygen -t ed25519
Install a public key ssh-copy-id alice@example.net

Which command should you use?

For a one-off upload to a standard SSH server, use the basic local-to-remote form. Add -r only for a directory, -P when the administrator supplied a nonstandard port, and -i when a particular key is required. For repeated transfers, configure an Ed25519 key and a host entry so the command remains short and predictable. Start with the modern default protocol; reserve -O for a confirmed compatibility case. When anything fails, test SSH first, rerun SCP with -v, and consult the remote service log if you administer that server.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.