October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk12 min

How to Copy Files From One Linux Server to Another: scp, rsync, and SFTP

Use scp for a one-time copy, rsync over SSH for repeat synchronization, and SFTP for interactive transfers. This guide covers commands, permissions, SSH keys, metadata, verification, and remote-to-remote designs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a single, straightforward transfer, use scp. For recurring copies, backups, or large directory trees, use rsync over SSH. Choose sftp when you need to browse a remote server and transfer selected files interactively. Every method depends on network reachability, an account that can log in to the destination, permission to read the source, and permission to write the destination.

Choose the right transfer method

The three commands solve different problems. The OpenSSH documentation describes scp simply: “scp copies files between hosts on a network.” It uses the SFTP protocol over an SSH connection, so it has the same authentication and transport security as an SSH login. The rsync manual calls rsync “a fast and extraordinarily versatile file copying tool”; its delta-transfer algorithm avoids retransmitting data that is already identical at the destination.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Need Best fit Reason
One file or one directory copied once scp One command with minimal setup.
Repeated synchronization, mirroring, or a large tree rsync over SSH Sends differences rather than recopying unchanged files and can retain selected metadata.
Browse, select, upload, download, or change permissions interactively sftp Provides a remote shell-like file-management session.
Preserve links, permissions, owners, groups, or devices rsync with suitable options Archive behavior requests metadata preservation, subject to account and filesystem limits.

All examples below use the placeholders user, server-a, server-b, and paths that you must replace. They are command patterns, not claims that a transfer has been run.

Plan the transfer before sending data

Identify the direction first: local to remote, remote to local, or server to server. Then write down the exact source and destination paths, the account that will own the transferred files, and whether the destination already contains a directory with the same name. This prevents a technically successful transfer from putting data in the wrong location.

Estimate whether the job is a one-time copy or a recurring synchronization. A one-time archive or configuration file rarely needs more than scp. A growing application-data tree benefits from rsync because subsequent runs can send only changed content. If a person must choose different files on each visit, SFTP’s interactive session avoids repeatedly editing a long shell command.

For a transfer between two remote hosts, also decide where the transfer process will run. Rsync cannot use one local process to connect independently to two arbitrary remote paths, so plan to execute it on one endpoint or stage the data through a machine with enough storage.

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.

Check connectivity and permissions first

A transfer can fail even when the command syntax is correct. Check the destination before sending data.

  1. Confirm that DNS or routing can reach the destination server and that SSH access is available.
  2. Confirm the destination account and target directory. A successful login alone does not prove that the account can create files there.
  3. Confirm that the source account can read every file you intend to copy.
  4. Decide whether the destination needs ordinary user ownership or whether an administrator must adjust ownership afterward.

Use an SSH preflight check such as:

ssh user@server-b 'id && test -d /remote/path && test -w /remote/path'

The command prints the remote identity and succeeds only if /remote/path exists and is writable by that account. Inspect source access locally with:

ls -l /source/path

If the destination directory does not exist, create it with an account authorized to do so, or select a directory that already exists. Do not grant broad privileges merely to make a transfer work; a dedicated account with only the required access is safer.

Remember that directory access depends on every parent directory in the path. An account may have permission on the final directory but still be blocked by a parent without execute permission. Check the path as the same account that will run the transfer, rather than testing only with an administrator account.

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

Copy a one-off file with scp

Local server to remote server

From the machine containing the source file, run:

scp /local/path/file user@server-b:/remote/path/

The final slash identifies the destination directory. The account must be able to read the local file and write in the remote directory. If the destination filename should change, specify the complete remote path instead:

scp /local/path/file user@server-b:/remote/path/new-name

Copy a directory recursively

Add -r for a directory and its contents:

scp -r /local/path/directory user@server-b:/remote/path/

This generally creates a directory named directory beneath /remote/path/. Check the target first so you do not place a tree one level deeper or overwrite an unintended location.

Remote server to local machine

Run the command on the machine that should receive the file:

scp user@server-a:/remote/path/file /local/path/

For a remote directory, combine the remote source with -r:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
scp -r user@server-a:/remote/path/directory /local/path/

Use a particular SSH identity

If the required private key is not the default identity, select it with -i:

scp -i /path/to/key /local/path/file user@server-b:/remote/path/

The private key should be readable only by its intended user. If the key has a passphrase, enter it when prompted or load it into an approved SSH agent; do not place the passphrase in a command or script.

What scp does and does not preserve

scp is convenient for a direct copy, but it is not a synchronization engine. Repeating the same command does not provide rsync’s difference-based update behavior. File ownership and other metadata may also be limited by the destination account, filesystem, and permissions. Use rsync when those requirements or repeatability matter.

Synchronize trees with rsync over SSH

Basic local-to-remote synchronization

Run:

rsync -avP /local/path/ user@server-b:/remote/path/

The options have distinct purposes: -a requests archive behavior, -v increases output, and -P combines progress reporting with retention of partial files. Rsync compares source and destination and transfers only the differences it detects, making it suitable for repeat jobs and large trees.

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.

Run the first synchronization manually so you can read the file list and any warnings. Once the path and ownership behavior are understood, the same command can be used by a scheduled job under the dedicated transfer account. Keep the command’s source and destination consistent across runs; changing either one can create a second tree instead of updating the intended tree.

Understand the trailing slash

The slash after the source directory changes the result:

  • /local/path/ means “copy the contents of this directory” into the destination.
  • /local/path generally means “copy this directory itself,” creating path beneath the destination.

Choose deliberately. A misplaced slash is a common reason for finding files under an unexpected extra directory after a migration. If you are unsure, use a dry run and inspect whether the output begins with the directory name you expect.

Preview changes before writing

Use a dry run when the destination matters or the path expression is unfamiliar:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
rsync -avP --dry-run /local/path/ user@server-b:/remote/path/

Review the listed files, destination, and deletion-related options before removing --dry-run. The examples here do not request deletion; adding destructive synchronization options requires a separate, carefully reviewed decision.

Metadata and privilege limits

Archive mode requests preservation of attributes such as links, permissions, ownership, groups, and timestamps where rsync and the underlying system allow it. The result can still be constrained by the destination account, filesystem support, mount options, and whether the account is permitted to set owners or groups. If ownership cannot be set during transfer, copy the files with an authorized account and perform a controlled ownership adjustment afterward rather than granting unnecessary administrator access to the transfer account.

Metadata preservation is not the same as permission elevation. Rsync can request an attribute, but the destination kernel and filesystem still decide whether the account may set it. Plan separately for content transfer and any post-transfer ownership or group assignment.

Remote source and remote destination

The rsync manual states that rsync copies to or from a remote host or locally; it does not support arbitrary copying between two remote hosts from one local rsync process. Therefore, this apparent form is not a general solution:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
rsync -avP user@server-a:/remote/path/ user@server-b:/remote/path/

Use one of these designs instead:

  • Run rsync on server-a, making server-b the destination. For example, log in to server-a and run rsync -avP /remote/path/ user@server-b:/remote/path/. Both endpoints must have rsync installed, and the account on server-a must be able to authenticate to server-b.
  • Stage the files through your local machine: pull from server-a, then push to server-b. This needs enough local storage and causes the data to traverse the local machine.
  • Use an approved administrative or backup workflow that runs a transfer process on one of the endpoints.

Do not assume that a local command can make one rsync process connect independently to two remote paths. Running the process on an endpoint also means checking that endpoint’s disk space, network route, SSH keys, and rsync installation before starting.

Use SFTP for an interactive session

SFTP is useful when you need to inspect a remote directory, transfer several selected items, or issue commands interactively rather than expressing the entire job in one shell command.

Start a session with:

sftp user@server-b

At the sftp> prompt, upload one file:

sftp> put /local/path/file /remote/path/file

Upload a directory recursively:

sftp> put -r /local/path/directory /remote/path/

When finished, close the session:

sftp> exit

The SFTP command set also includes a remote chmod operation for changing permissions when the account is allowed to do so. Use it narrowly and verify the resulting mode; changing permissions does not grant ownership or bypass filesystem restrictions.

Compared with scp, SFTP is less convenient for a scripted one-off because it requires an interactive session. Compared with rsync, it is not specialized for delta-based synchronization of an entire tree. Its advantage is control: you can inspect the remote location, transfer only the files selected during that session, and make a limited permission adjustment without building a larger automation script.

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

Set up key-based authentication for repeat transfers

Password prompts are acceptable for an occasional manual copy, but unattended backups and scheduled synchronization need a safer non-interactive authentication design. Install a public key for the destination account with:

ssh-copy-id user@server-b

The utility installs the key in that account’s authorized_keys file. Test the login independently before adding a transfer job:

ssh user@server-b 'id'

Keep the corresponding private key readable only by the intended local user. Protect a passphrase with an SSH agent or an organization-approved secret-management process. A key should belong to the limited-purpose account used for the transfer, not automatically to a highly privileged administrator account.

Use the same account and identity in the eventual scp, rsync, or sftp command that you tested with SSH. A key installed for one username does not authenticate a different destination account, and successful key authentication still does not grant write access to every directory.

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

Verify the result and diagnose failures

Authentication errors

If SSH reports that authentication failed, verify the username, destination host, selected identity file, and whether the public key is installed for that exact account. Test with plain ssh first; fixing login independently makes scp, rsync, and SFTP failures easier to isolate.

Permission denied on the source

A transfer process can copy only files that its source account can read. Inspect ownership and mode with ls -l, then use an account with legitimate access or adjust permissions through your normal administration process.

Permission denied on the destination

Check the target directory with the preflight command. The account may be able to log in but lack write or execute permission on one of the parent directories. Select an authorized destination or have an administrator create and assign the directory; do not solve a directory problem by making the entire filesystem writable.

Unexpected directory nesting

With rsync, recheck whether the source ended in a slash. With scp, confirm whether you specified a destination directory or a complete filename. A dry run is the safest way to inspect rsync’s planned paths before writing.

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

Interrupted or incomplete transfer

Rsync’s -P option displays progress and retains partial files, which is useful when a large transfer is interrupted. Rerun the same command after connectivity is restored and inspect the output. For scp or SFTP, restart the operation and verify the resulting file size and application-level integrity when the data is important.

Metadata did not match

Archive mode cannot override destination restrictions. Confirm that the destination filesystem supports the requested attributes and that the account is allowed to set them. Ownership may require an authorized post-transfer step.

Transfer appears successful but the application cannot use the files

Check the destination path, owner, group, permissions, and completeness of the files from the perspective of the application account. A command returning without an obvious error confirms transport activity, not that an application has the expected access or directory layout.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Practical decision workflows

One configuration file or archive

Run scp from the source side, specify the destination account and directory, and verify the file remotely. Add -i only when a particular key is required.

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

Nightly application-data synchronization

Use rsync over SSH with archive, verbose, and progress options. First run the command with --dry-run, then schedule the reviewed command under a dedicated account with key-based authentication. Keep the source trailing-slash choice consistent so every run targets the same directory layout. Confirm that the account can read newly created source files and write the destination as the data set grows.

Selective manual collection

Open an SFTP session, inspect the remote location, use get or put for the specific files, and exit when finished. This avoids constructing a long command when the selection changes from one session to the next.

Moving data directly between two remote servers

Do not launch a two-remote-path rsync command from your workstation. Run rsync on one server with the other as its SSH peer, or stage the data locally if endpoint execution and authentication cannot be arranged. In the staging design, account for local disk capacity and the fact that the data crosses the local machine.

Security and operational checklist

  • Use a destination account limited to the directories and operations required.
  • Confirm the source and destination paths before every first run.
  • Use --dry-run for unfamiliar rsync jobs.
  • Protect private keys and use an agent or approved secret manager for passphrases.
  • Do not assume a successful SSH login implies write permission.
  • Consider ownership, groups, permissions, links, and filesystem support before relying on archive behavior.
  • For important data, verify that the destination file is complete and usable, not merely that the command returned without an obvious error.
  • When a transfer is scheduled, test the exact account, key, paths, and environment manually before relying on unattended runs.

Frequently Asked Questions

Should I use scp or rsync to copy files between Linux servers?

Use scp for a straightforward one-time file or directory copy. Use rsync over SSH for repeated synchronization, backups, or large trees because it transfers only differences and can request metadata preservation.

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

How do I copy a directory with scp?

Add the recursive option: scp -r /local/path/directory user@server-b:/remote/path/. Confirm the destination first, because this generally creates the source directory beneath the destination directory.

How can I avoid entering my password for every transfer?

Install an SSH public key for the destination account with ssh-copy-id user@server-b, then test ssh user@server-b 'id'. Protect the private key and use an SSH agent or approved secret manager for its passphrase.

Can rsync copy directly from one remote server to another?

Not from one local rsync process using two remote paths. Run rsync on one endpoint with the other as its destination, or stage the files through a local machine with enough storage.

What does the trailing slash in an rsync source path do?

A source ending in / copies the directory’s contents into the destination. Without the slash, rsync generally copies the directory itself and creates that directory beneath the destination.

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

Why does SSH work but the file transfer fail with permission denied?

Login permission and filesystem write permission are separate. Check the destination directory and every parent with the transfer account, and verify that the source account can read the files. An administrator may need to create the directory or adjust ownership.

When is SFTP better than scp?

SFTP is preferable when you need to browse a remote directory, select different files during each session, upload or download interactively, or issue a narrowly scoped remote permission command such as chmod.

Does rsync archive mode guarantee that owners and permissions will match?

No. Archive mode requests preservation, but destination account privileges, filesystem support, mount options, and ownership rules can prevent some attributes from being applied. Plan an authorized post-transfer ownership step when necessary.

The Bottom Line

Choose scp for a simple one-time copy, rsync -avP over SSH for repeatable synchronization, and sftp for interactive file selection. Check reachability and permissions first, use a dry run for unfamiliar rsync paths, protect SSH keys, and remember that rsync does not natively connect one local process to two remote hosts.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.