πŸŒ‹ The Problem

Let’s assume that you have a file that you need to get off of a server, or one that you want to put on a server. It would be a bit long winded to go and setup some form of FTP client, or to configure a share to deal with this small task.

Fortunately, this is where scp comes in. SCP allows you to securely transfer files between devices through the command line. And it comes preinstalled on almost every Linux system.

🧭 Usage

It’s super easy to get going with scp.

Remote to local:

scp [email protected]:/remote/file.md /local/directory/

This will transfer file.md from host.com to /local/directory on your device. You would be prompted to enter the password for username before the transfer could continue.

Remote to remote:

scp [email protected]:/source/file.md [email protected]:/destination/file.md

This will transfer file.md from hostA to hostB. You would be prompted to enter your password for both hosts to run this command.

Local to remote:

scp /local/file.md [email protected]:/remote/

This will transfer file.md to host.com from your machine. You will be prompted to enter the password for host.com to run this command.

⛰️ Limitations

Whilst scp is a very powerful command, it does have some limitations.

Incompatible with non-Linux machines:

You can only use scp to transfer files between devices running Unix-based systems.

Limited to your permissions:

When it comes to scp, there is no sudo. You can only transfer files to directories that you own.

Want to get around this? You can just copy the files to a directory you own on the remote machine, and then SSH into it and move them with sudo.