Operations 7 min read

Master Secure File Transfers with SCP: Options, Examples, and Password‑less Setup

This guide explains how SCP securely copies files over SSH, details each command‑line option, provides practical usage examples—including recursive folder transfers—and shows how to configure password‑less authentication with SSH keys for automated scripting.

ITPUB
ITPUB
ITPUB
Master Secure File Transfers with SCP: Options, Examples, and Password‑less Setup

SCP Overview

SCP copies files between two hosts over a network, encrypting data during transmission by leveraging SSH; it shares SSH's authentication mechanisms and security level.

File Replacement Behavior

When copying a file, SCP overwrites the target if it already exists; if the target does not exist, SCP creates an empty file first and then writes the source content into it.

SCP Options

-1: Force SSH1 protocol.

-2: Force SSH2 protocol.

-4: Force IPv4 address format.

-6: Force IPv6 address format.

-B: Batch mode (no password prompt).

-C: Enable compression (passes -C to SSH).

-p: Preserve modification, access times, and permissions.

-q: Suppress progress meter.

-r: Recursively copy entire directories.

-c cipher: Choose cipher for data encryption.

-F ssh_config: Specify an alternative SSH configuration file.

-i identity_file: Use a private key for RSA authentication.

-l limit: Limit bandwidth in Kbit/s.

-P port: Specify remote SSH port (capital P).

-S program: Specify the program for encrypted transport.

-o ssh_option: Pass options to SSH in ssh_config format.

SCP Usage Examples

Example 1 – Copy a file with explicit user: scp /phppro/Db.php [email protected]:/Db.php This copies /phppro/Db.php to the root directory of the remote host, prompting only for the password of user root.

Example 2 – Copy a file without specifying user: scp /phppro/Db.php 192.168.18.130:/Db.php Since no user is given, SCP asks for both username and password; many systems default to root if no user is provided.

Example 3 – Recursively copy a directory: scp -r /phppro [email protected]:/phppro The -r flag copies the entire /phppro directory. If the target directory does not exist, SCP creates it before transferring contents.

Password‑less Transfer Setup

Repeated password prompts hinder automation. To enable password‑less SCP, generate an SSH key pair and distribute the public key to the remote host. ssh-keygen -t rsa Accept the default file location ( /root/.ssh/id_rsa) and press Enter twice when asked for a passphrase to create an empty passphrase.

After key generation, three files appear in $HOME/.ssh/: id_rsa (private key), id_rsa.pub (public key), and known_hosts. Copy id_rsa.pub to the remote host's $HOME/.ssh/ directory and rename it to authorized_keys. Subsequent SCP commands will no longer require a password or passphrase.

Conclusion

Understanding SCP options, usage patterns, and password‑less configuration empowers efficient and secure file transfers in Linux environments.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

SSHfile transferPasswordlessscp
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.