Skip to content
Follow
Ubuntu Linux

A Guide to SCP: Secure File Transfer on Ubuntu

Richard
Written by
Richard
Jan 17, 2024 Updated Aug 13, 2026 4 min read
How to Enable or Disable Microsoft Defender Cloud Protection
How to Enable or Disable Microsoft Defender Cloud Protection

SCP (Secure Copy) is a built-in command-line tool that lets you securely move files and folders between computers over a network. It uses SSH (Secure Shell) to lock down and encrypt your data while it travels, keeping your files safe from snoops.

You can use SCP to copy a file from your local machine to a remote Ubuntu server, or pull files back down to your own desktop. For example, moving a large project folder to an Ubuntu 22.04 LTS development server takes just a single command.

⚡ Quick Answer

Use the `scp` command in your Ubuntu terminal to securely transfer files and directories. To copy a file from local to remote, use `scp /path/to/local/file username@remote:/path/to/destination`. For remote to local, reverse the source and destination paths.

SCP command examples

The SCP command makes SCP file transfer on Ubuntu simple by letting you securely copy files between computers. The basic format for the SCP command is `scp [options] [user@]source_host:file [user@]destination_host:file`. You can add options to change how the transfer works, like the connection method or port.

The scp command syntax uses the following format:

💻Code
scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2
  • OPTION – scp options that specify cipher, SSH configuration, SSH port, limit, recursive copy, etc.
  • [user@]SRC_HOST:]file1 – path to the source file.
  • [user@]DEST_HOST:]:file2 – path to the destination file.
📝Good to Know
Local files can be specified using an absolute or relative path, while remote file names must include a user and host specification.

The most commonly used options for the SCP command are:

  • -P - Specifies the remote host ssh port.
  • -p - Preserves file modification and access times.
  • -q - Use this option to suppress the progress meter and non-error messages.
  • -C - This option forces scp to compress the data as it is sent to the destination machine.
  • -r - This option tells scp you to copy directories recursively.

Transferring files

Sending a single file from your computer to another is easy with the SCP command. To move a local file to a remote computer, use a command like `scp [options] /path/to/local/file username@remote:/path/to/destination`. This tells SCP exactly which file to send and where it should end up on the other machine.

💻Code
scp [options] /path/to/local/file username@remote:/path/to/destination

For example, to transfer a file named `example.txt` from the local machine to a remote machine with the IP address `192.168.0.2`, use the following command:

💻Code
scp example.txt username@192.168.0.2:/home/username/

To transfer a file from a remote machine to the local machine, use the following command:

💻Code
scp [options] username@remote:/path/to/file /path/to/destination

For example, to transfer a file named `example.txt` from a remote machine with the IP address `192.168.0.2` to the local machine, use the following command:

💻Code
scp username@192.168.0.2:/home/username/example.txt /home/localuser/

If you want to save the file under a different name, specify the new file name at the destination. If SSH on the remote host is listening on a port other than the default 22, then you can specify the port using the -P argument:

💻Code
scp -P 2322 example.txt username@192.168.0.2:/home/username/newName.txt

Transferring directories

Copying a whole folder and everything inside it to another computer is simple with SCP. Use the `-r` option to tell SCP to copy recursively, grabbing the directory and all its contents. The command to complete an SCP transfer of a directory looks like `scp [options] -r /path/to/local/directory username@remote:/path/to/destination`.

💻Code
scp [options] -r /path/to/local/directory username@remote:/path/to/destination

For example, to transfer a directory named `example` from the local machine to a remote machine with the IP address `192.168.0.2`, use the following command:

💻Code
scp -r example/ username@192.168.0.2:/home/username/

To transfer a directory from a remote machine to the local machine, use the following command:

💻Code
scp [options] -r username@remote:/path/to/directory /path/to/destination

For example, to transfer a directory named `example` from a remote machine with the IP address `192.168.0.2` to the local machine, use the following command:

💻Code
scp -r username@192.168.0.2:/home/username/example/ /home/localuser/

That should do it!

Conclusion:

  • Using the SSH protocol, SCP (secure copy) is an essential command-line utility for securely transferring files and directories between networked devices.
  • It provides a secure way to transfer files over a network and is particularly useful for protecting sensitive information on insecure networks.
  • Understanding the SCP command's basic syntax and commonly used options is crucial for efficient usage.
  • The examples demonstrate transferring files and directories between local and remote machines using SCP on Ubuntu Linux.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Allow Remote Access to MariaDB in Ubuntu Linux
Ubuntu Linux How to Allow Remote Access to MariaDB in Ubuntu Linux
How to Install WildFly on Ubuntu Linux
Ubuntu Linux How to Install WildFly on Ubuntu Linux
How to Install 1Password on Ubuntu Linux
Ubuntu Linux How to Install 1Password on Ubuntu Linux
How to Setup Let's Encrypt with Apache on Ubuntu Linux
Ubuntu Linux How to Setup Let's Encrypt with Apache on Ubuntu Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

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