SCP Command Examples for Linux

The SCP (Secure Copy Protocol) command is a powerful tool in Linux, enabling users to copy files between hosts on a network. It's particularly useful when you need to transfer files from a remote server to your local machine or vice versa. In this article, we'll explore the SCP command with examples, helping you understand its syntax and usage.

an image of a text message with the words linux sp command examples in green and black
an image of a text message with the words linux sp command examples in green and black

SCP is a client-server based application, which means it uses a client on the local machine and a server on the remote machine to facilitate the file transfer. It's important to note that the remote server must have an SCP server running to accept connections from the client.

SCP Command in Linux {13 Examples}
SCP Command in Linux {13 Examples}

Basic SCP Command Syntax

The basic syntax of the SCP command is as follows:

Transfer Files Securely with SCP
Transfer Files Securely with SCP

scp [options] source destination

Here, 'source' refers to the file or directory you want to copy, and 'destination' is where you want to copy it to. The 'options' are various flags that can be used to customize the behavior of the SCP command.

Struggling With the Linux Secure Copy Command? Use This scp Example
Struggling With the Linux Secure Copy Command? Use This scp Example

Copying a File from Local to Remote

To copy a file from your local machine to a remote server, use the following command:

scp local_file remote_username@remote_host:remote_directory

AMP Validation WordPress Error Resolution Guide - ARKIT
AMP Validation WordPress Error Resolution Guide - ARKIT

For example, if you want to copy a file named 'example.txt' from your local machine to the '/home/user' directory on a remote server with the IP address 192.168.1.100, you would use:

scp example.txt user@192.168.1.100:/home/user

Copying a File from Remote to Local

50 Essential Linux Commands for Beginners and SysAdmins
50 Essential Linux Commands for Beginners and SysAdmins

To copy a file from a remote server to your local machine, use the following command:

scp remote_username@remote_host:remote_file local_directory

28 Essential Linux Commands for Daily Use: Complete Beginner to Admin Cheat Sheet
28 Essential Linux Commands for Daily Use: Complete Beginner to Admin Cheat Sheet
Using scp Command in Linux: 10 Practical Examples Explained
Using scp Command in Linux: 10 Practical Examples Explained
Linux Commands Cheat Sheet for Hackers & Developers (Must Know)🔥🚀
Linux Commands Cheat Sheet for Hackers & Developers (Must Know)🔥🚀
SCP Command Guide: Secure File Transfers
SCP Command Guide: Secure File Transfers
a black and white photo with a penguin on it's back side, surrounded by words that read cli commands
a black and white photo with a penguin on it's back side, surrounded by words that read cli commands
Linux Commands
Linux Commands
a black and yellow flyer with linux commands
a black and yellow flyer with linux commands
Ultimate Linux Commands Cheat Sheet for DevOps & Telecom
Ultimate Linux Commands Cheat Sheet for DevOps & Telecom
an image of a computer screen with the text art index of the bash command line for linux
an image of a computer screen with the text art index of the bash command line for linux
a computer screen with the text linux grep command examples written in bold colors on it
a computer screen with the text linux grep command examples written in bold colors on it
the linux commands for devops poster
the linux commands for devops poster
Linux Command Syntax: Understanding the Basics
Linux Command Syntax: Understanding the Basics
Linux Commands Cheat Sheet for Beginners 2026
Linux Commands Cheat Sheet for Beginners 2026
30 LINUX COMMANDS EVERY DEVELOPER SHOULD KNOW
30 LINUX COMMANDS EVERY DEVELOPER SHOULD KNOW
Top 15 Kali Linux Commands Every Ethical Hacker Should Know🚀🎯
Top 15 Kali Linux Commands Every Ethical Hacker Should Know🚀🎯
Secure File Transfer with SCP: Linux Command Guide 🔒💻
Secure File Transfer with SCP: Linux Command Guide 🔒💻
Linux Command Cheat Sheet for Beginners
Linux Command Cheat Sheet for Beginners
a black and white poster with the words basic linux commands
a black and white poster with the words basic linux commands
Linux Terminal Customization Tips, Linux Networking Commands Cheat Sheet, Linux Terminal Prompt Customization, Polecenia Linux Cheat Sheet, Linux Kernel Module Programming Guide, Linux Terminal Coding, Linux Commands, Linux Chmod Command Guide, Linux Ls Command Output
Linux Terminal Customization Tips, Linux Networking Commands Cheat Sheet, Linux Terminal Prompt Customization, Polecenia Linux Cheat Sheet, Linux Kernel Module Programming Guide, Linux Terminal Coding, Linux Commands, Linux Chmod Command Guide, Linux Ls Command Output
Ultimate Linux Commands Cheat Sheet for Beginners
Ultimate Linux Commands Cheat Sheet for Beginners

For instance, to copy a file named 'example.txt' from the '/home/user' directory on a remote server with the IP address 192.168.1.100 to your local 'downloads' directory, you would use:

scp user@192.168.1.100:/home/user/example.txt downloads/

SCP Command Options

SCP offers several options to customize the file transfer process. Here are a few commonly used ones:

Preserving File Permissions

By default, SCP does not preserve the original file permissions. To preserve them, use the '-p' option:

scp -p local_file remote_username@remote_host:remote_directory

Copying Directories

To copy an entire directory and its contents recursively, use the '-r' option:

scp -r local_directory remote_username@remote_host:remote_directory

Displaying Progress

To see the progress of the file transfer, use the '-P' option. Note that this option is capital 'P', not lowercase 'p':

scp -P local_file remote_username@remote_host:remote_directory

SCP vs. SFTP: Which to Use?

SFTP (SSH File Transfer Protocol) is another protocol used for secure file transfers. So, which one should you use?

SCP is generally faster and simpler to use, as it's designed for quick, one-off file transfers. On the other hand, SFTP provides a more interactive session, allowing you to perform multiple file operations (like creating directories, renaming files, etc.) in a single connection. It's also easier to use with GUI clients like FileZilla.

In conclusion, the choice between SCP and SFTP depends on your specific needs. If you're looking for a quick, simple file transfer, SCP might be your best bet. But if you need more interactive features or plan to use a GUI client, SFTP could be more suitable. Happy transferring!