If you manage a live server or a home server, transferring files between machines—whether local or remote—is often essential. While there are several ways to do this, one of the simplest and most secure methods is using the scp
(secure copy) command. Unlike FTP, SCP encrypts your files and credentials during transfer, ensuring privacy and security without needing to log in to the remote machine.
Since SCP relies on SSH (Secure Shell), you only need the SSH credentials for the source and destination servers. In addition to transferring files between local and remote machines, SCP also allows transferring files directly between two remote servers from your local machine. Let’s walk through some common use cases and commands.
Prerequisites #
- SSH access to the Linux server with the user that you want to copy files with (e.g root)
- SSH password for the user – the SCP command will ask you to input a password.
Basics of the SCP Command #
The basic syntax for copying a file from your local machine to a remote server is:
scp localmachine/path_to_the_file username@server_ip:/path_to_remote_directory
Here, replace;
-
username
with your remote server’s username (e.g root or any other user) 10.0.0.75
with the server’s IP, or hostname/remote/directory
with your desired directory on the server. e.g /home/. The directory should be existing on the demote server
For example, to copy a file called flameshot.rpm
located on my laptop in my current working directory to a Linux server with hostname cp.tke.co.ke in a directory /root/dbbackup, I will do as below;
scp flameshot.rpm root@cp.tke.co.ke:/root/dbbackup
If your Linux server uses a custom SSH port, other than port 22, you will need to specify the port using the -P flag, as below
scp -P 2222 flameshot.rpm root@cp.tke.co.ke:/root/dbbackup
In the above command, note that P is uppercase and 2222 is to be replaced with your own custom port.
You will then be prompted to input the user’s SSH password.
Put the password and hit Enter. As it is with SSH platforms, you will not see the password being typed. Ensure to type it in accurately then hit Enter to copy the file

Copying a Single File to a Remote Server #
To copy a single file from your local machine to a remote server, use:
scp /path/to/local_file username@server_ip:/path_to_remote_directory
Copying a Directory to a Remote Server #
To transfer an entire directory, include the -r
flag for recursive copying:
scp -r /local/path/to/directory username@server_ip:/path_to_remote_directory/
If you use a custom port, you will have it in the format below. The command below copied a folder called Downloads from my current working directory to a remote server in a directory /root/dbbackup.
Again replace 2222 with your own port.
scp -P 2222 -r Downloads root@cp.tke.co.ke:/root/dbbackup
Note: Ensure that your source path doesn’t end with a forward slash (/
), while the destination path must end with one.

Copy All Files in a Local Directory to a Remote Directory #
If you only want to copy all files within a directory without transferring the directory itself, add a /*
after the source directory:
scp -r /local/path/to/directory/* username@server_ip:/path_to_remote_directory/
Copying Files from a Remote Server to Your Local Machine #
You can also copy files in reverse—from a remote server to your local machine. The syntax is similar:
scp username@server_ip:/path_to_remote_file /local/path/to/destination
To copy an entire directory from the remote server:
scp -r username@server_ip:/path_to_remote_directory /local/path/to/destination/
Below, I want to copy a directory called Downloads from /root/dbbackup/Downloads on the remote server to my local machine, this path /home/tke/utilityFiles/

Copy Files Between Directories on the Same Server from Your Local Machine #
With SCP, you can transfer files between directories on the same server directly from your local machine.
Note that here, you are on your local machine but you are copying files between remote directories without SSHing to the remote server.
This can save time compared to logging in via SSH:
scp username@server_ip:/source_directory/file username@server_ip:/destination_directory/
For copying an entire directory:
scp -r username@server_ip:/source_directory username@server_ip:/destination_directory/
Copy Files Between Two Remote Servers from Your Local Machine #
Another great feature of SCP is the ability to move files between two remote servers from your local machine without needing to log in to either server:
scp username@server1_ip:/path_to_file username@server2_ip:/destination_path
For copying an entire directory:
scp -r username@server1_ip:/source_directory username@server2_ip:/destination_directory
Conclusion #
With SCP, securely transferring files between servers or directories is straightforward and highly efficient. Mastering this simple command opens up powerful capabilities for managing files across servers. Now that you’ve got the basics down, you’re ready to make your Linux file transfers secure and efficient. Happy transferring!