DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Seth
Seth

Posted on • Originally published at saluki.tech

How to transfer files between Linux devices with scp

πŸŒ‹ 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 username@host.com:/remote/file.md /local/directory/
Enter fullscreen mode Exit fullscreen mode

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 username@hostA.com:/source/file.md username@hostB.com:/destination/file.md
Enter fullscreen mode Exit fullscreen mode

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 username@host.com:/remote/
Enter fullscreen mode Exit fullscreen mode

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 Linux distributions.

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.

This article was originally published on https://saluki.tech. For more articles like this, please take a look.

Top comments (2)

Collapse
giovannicodes profile image
Giovanni CortΓ©s

"You can only use scp to transfer files between devices running Linux distributions." This is no 100% true, because you can transfer between Linux and macOS and BSD flavors.

Collapse
saluki profile image
Seth Author

True, it would have been more accurate for me to say Unix-based systems.

πŸ€” Did you know?

Β 
πŸŽ™ DEV hosts some podcasts that you can find on our Podcasts page.