SCP Command Linux: How To Secure File Transfers

SCP Command Linux

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

Transferring files securely is essential for managing Linux systems. Whether you are moving sensitive files between local computers, transferring data between servers, sending backup files to a remote server, retrieving logs from a hosted machine, or synchronizing directories across various systems. That’s where the scp command Linux, comes into play.

SCP (Secure Copy Protocol) is a network protocol used to securely transfer files and folders between Linux (Unix) systems over a network. In this guide, we explain what a Linux SCP command is and top examples to master in 2025!

What Is the SCP Command Linux?

SCP (Secure Copy Protocol) is a command-line tool that lets you securely transfer files and directories between two locations. This command-line utility enables secure file transfers between hosts over a network that uses the SSH protocol, which encrypts data during the transfer to safeguard it from interception. Whether you are copying files from your local computer to a remote server or moving files between two Linux machines, SCP guarantees a safe and quick process.

When you use scp to move data, both the files and the password are encrypted, preventing anyone from intercepting sensitive information. SCP relies on the SSH protocol for authentication and encryption.

Why Use SCP for Secure File Transfers?

SCP is especially valuable for users who are interested in PCI Compliance. Complying with strict security parameters often means closing Port 21 on your server, which FTP uses. SCP is based on the SSH protocol, so it is more secure and uses Port 22.

Basic Syntax of the SCP Command

Before we discuss how to use the scp command, let’s first look at the basic syntax.

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

The syntax for the scp command in Linux is as follows:

scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2 

OPTION – options for scp like cipher, ssh configuration, ssh port, limit, recursive copy, etc.

  • [user@]SRC_HOST:]file1 – This is the path to the source file. The username on the source machine and the hostname (or IP address) of the source machine are required when the file is on a remote machine.
  • [user@]DEST_HOST:]file2 – This is the path to the destination file. The username on the destination machine and the hostname (or IP address) of the destination machine are needed when the file is on a remote machine.

When working with remote files, start by specifying the user and host. Make sure to use an account that has read access to the files you want to copy from the source system. You also need an account with write access to the destination directory where you will save the files.

Most Common SCP Command Examples

Copy a file from local to remote

In the example below, we transfer a sample file from a local host to a remote server:

scp Desktop/sample_example.txt root@136.183.142.28:/home/remote_dir

The command contains the following details:

  • Desktop/sample_example.txt: This is the name and location of the file being transferred.
  • [email protected]: This is the username and IP address of the remote server.
  • /home/remote_dir: This is the destination where the copied file will be saved.

To copy the file named file.txt, use the remote_username for the user on the remote server, and 10.10.0.2 as the server’s IP address. The path /remote/directory indicates where you want to copy the file. If you don’t provide a remote directory, the file will go to the home directory of the remote user.

You will need to enter the user’s password, and then the transfer will begin.

remote_username@10.10.0.2's password:<br>file.txt 100% 0 0.0KB/s 00:00

If you leave out the filename in the destination, the file will keep its original name. To save it with a different name, specify the new name:

scp file.txt remote_username@10.10.0.2:/remote/directory/newfilename.txt

If the SSH on the remote server is using a port other than the default 22, you can indicate the port with the -P option:

scp -P 2322 file.txt remote_username@10.10.0.2:/remote/directory

To copy a directory along with all its files, use the scp command with the -r flag, which will copy the entire directory and its contents:

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

scp -r /local/directory remote_username@10.10.0.2:/remote/directory

When using wildcards like * or ? to select specific files or directories, make sure to enclose the path with wildcard characters in quotes (” “) or single quotes (‘ ‘). For instance, to copy all .txt files from the local Projects directory to the Projects directory on the remote server:

scp "~Projects/*.txt" remote_username@10.10.0.2:/home/user/Projects/

To keep the file’s metadata, which includes details like ownership and creation date, use the -p option. For example, to copy file.txt to the remote directory while preserving the metadata, type:

scp -p file.txt remote_username@10.10.0.2:/remote/directory/

Copy a file from remote to local

Transfer a File from a Remote System to a Local System using the scp Command
To transfer a file from a remote system to a local one, specify the remote path as the source and the local path as the target.

For instance, to transfer a file called file.txt from a remote server with the IP address 10.10.0.2, execute the following command:

scp remote_username@10.10.0.2:/remote/file.txt /local/directory

If you have not configured a passwordless SSH login for the remote server, you will need to input the user password.

Transfer a File Between Two Remote Systems with the scp Command

Unlike rsync, scp allows you to transfer files from one remote machine to another without logging into either server.

The command below will copy the file /files/file.txt from the remote host host1.com to the /files directory on the remote host host2.com.

scp user1@host1.com:/files/file.txt user2@host2.com:/files

You will need to enter the passwords for both remote accounts. The data will be sent directly from one remote host to the other.

To direct the traffic through the machine where the command is run, use the -3 option:

scp -3 user1@host1.com:/files/file.txt user2@host2.com:/files

Advanced SCP Command Linux Examples

Using SSH Options – You can add extra SSH options like -o to modify the SSH connection. In this case, we use ProxyJump to connect through a jump host before reaching the source host:

$ scp -o "ProxyJump user@jump_host" username@from_host:file.txt /local/directory/

Quiet Mode – The -q option turns off the progress meter and warning/diagnostic messages, making the transfer less noisy:

$ scp -q username@from_host:file.txt /local/directory/

Verbose Mode for Debugging – The -v option activates verbose mode, which shows debugging messages. This is useful for fixing connection and configuration problems:

$ scp -v username@from_host:file.txt /local/directory/

Recursive Copy with Compression and SSH Options – This example merges several options to carry out a recursive copy with compression and specific SSH options:

$ scp -r -C -o "ProxyJump user@jump_host" username@from_host:/remote/directory/ /local/directory/

Here are a few tips to keep in mind:

  • Verify that it works with the remote host’s settings and permissions.
  • Conduct extensive testing in a secure environment prior to going live.
  • Example of SCP command: scp -r [email protected]:/var/www/html/ /home/hydn/backups/test/.
  • The host can be specified as either an IP address or a domain name.
  • You will be prompted for the SSH password after executing the command.
  • These instructions are suitable for Mac users with “Terminal” or for those using WinSCP on a Windows PC/server.
  • Exercise caution when transferring a source file to a destination file.

Summary

This guide provides a comprehensive overview of SCP command Linux, offering both basic and advanced examples to help you understand their usage. SCP allows you to transfer files between Linux machines over a network securely. It leverages existing command-line utilities and SSH (Secure Shell) protocol features, ensuring a smooth and effective way to manage files. With SCP, you can easily copy files and directories from one location to another while maintaining secure connections and data integrity.

FAQ’s

1: Which port is used by SCP?

SCP operates on port 22, the same as SSH.

2: Is SCP quicker than SFTP?

SCP tends to be faster for smaller files but does not have resume capabilities.

3: Can I transfer multiple files using SCP?

Yes, simply list them:

scp file1.txt file2.txt user@host:/path/

4: Does SCP have progress indicators?

Yes! Most Linux distributions support -v or display progress automatically.

5: Is SCP considered outdated?

OpenSSH has labeled SCP as legacy, yet it remains commonly used. For enhanced security, consider using rsync or sftp for future needs.

Areeba Nauman
Areeba is a Content Writer with expertise in web content and social media, she can simplify complex concepts to engage diverse audiences. Fueled by creativity and driven by results, she brings a unique perspective and a keen attention to detail to every project she undertakes with her creativity and passion for delivering impactful content strategies for success. Let's connect on Linkedin: https://www.linkedin.com/in/areeba-bhatti/
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!