scp

2026/05/20

Practical Guide to Using the SCP Command for Secure File Transfer in Linux

If you are active in the world of networking and server management, you have certainly faced the challenge of transferring files quickly and securely between a local system and a remote server. Various tools exist for this purpose, but the SCP command remains one of the most popular choices for developers and system administrators due to its simplicity, speed, and high security.

What is SCP and Why Do We Use It?

SCP stands for Secure Copy Protocol. This tool allows you to move files and directories between two hosts. The key point is that SCP operates based on the SSH protocol; this means all data is encrypted during transit, ensuring the security of your information.

Main Advantages:

  • Security: Utilizes SSH encryption.
  • Pre-installed: It is available by default on most Linux distributions and macOS.
  • Speed: Fast performance in transferring large files compared to similar methods.

Basic Syntax

The formula for using this command is very simple: scp [Options] [Source] [Destination]

Practical Examples

1. Transferring a File from Local System to Server

Imagine you have a file named app.tar.gz and you want to move it to the home folder on the destination server:

scp app.tar.gz username@server_ip:/home/username/

2. Downloading a File from Server to Local System

If you intend to download a file, such as a database backup, from the server to your own system for review, use this command:

scp username@server_ip:/home/username/db_backup.sql /Users/name/Downloads/

3. Transferring an Entire Directory (Folder)

To move a folder and all its subdirectories, you must use the -r flag:

scp -r project_folder username@server_ip:/var/www/projects/

Technical Tips for Optimization

  • Changing the Port: If your server uses a port other than the default (22) for SSH, you must specify it with the -P parameter: scp -P 2222 file.txt user@ip:/path
  • Using SSH Keys: To avoid repeatedly entering passwords, it is recommended to define your system's SSH key on the server. This makes file transfers automatic and much faster.
  • Preserving File Metadata: By using the -p parameter, you can preserve characteristics like modification times and permissions on the destination.
saleh askari
saleh askari

Thank you so much for reading this blog post.