Objective of this article:
You have two Linux machines (or a local computer and a remote server), and you want to transfer files between them over the network, securely. We’ll see three classic tools:scp,rsync, andsftp.
π¦ Why transfer files over SSH?
SSH (Secure Shell) is not just for remote terminal access. It can also be used to transfer files securely. Unlike FTP or HTTP, all data is encrypted end-to-end.
Youβll most often use these methods in the following cases:
- Transfer configuration files or scripts to a remote server.
- Back up folders from a server to your computer.
- Copy a file from one machine to another (via command line).
- Synchronize a folder between two machines (e.g., for automation).
π Common requirement: SSH access
For all the methods below, you need:
- A user with SSH access to the server.
- A public/private SSH key pair set up (optional but highly recommended).
Example connection:
ssh user@server_ip
π 1. scp β Quick and simple
scp (secure copy) is the easiest tool. It allows copying a file or folder between two systems via SSH.
β€ Syntax:
scp SOURCE DESTINATION
β€ Examples:
βΈ Send a file to a remote server:
scp myfile.txt admin@192.168.1.10:/home/admin/
βΈ Retrieve a file from the server:
scp admin@192.168.1.10:/etc/nginx/nginx.conf .
βΈ Copy an entire folder:
scp -r myfolder/ admin@192.168.1.10:/home/admin/
β
Pros: Simple, available by default on most systems
β Cons: No resume support, not efficient for large transfers
β‘ 2. rsync β Efficient and powerful
rsync is ideal for syncing files and folders. It only sends changes, making it very efficient.
β€ Syntax:
rsync [options] SOURCE DESTINATION
β€ Examples:
βΈ Send a folder to the server:
rsync -avz myfolder/ admin@192.168.1.10:/home/admin/myfolder/
βΈ Retrieve a folder from the server:
rsync -avz admin@192.168.1.10:/etc/nginx/ ./nginx_backup/
β
Pros: Fast, resumable, intelligent
β Cons: Needs to be installed (not always by default on minimal servers)
π§ 3. sftp β Interactive and familiar
sftp is an interactive tool similar to FTP, but secured with SSH.
β€ Connect to a server:
sftp admin@192.168.1.10
Youβll enter an SFTP session like this:
sftp>
β€ Commands to know:
lsβ list filescdβ change remote directorylcdβ change local directoryget fileβ download a fileput fileβ send a file
Example:
sftp> put myfile.txt
sftp> get remote_file.txt
β
Pros: Familiar for FTP users, allows browsing
β Cons: Less scriptable, slower for large files
π Summary table
| Tool | Use case | Pros | Cons |
|---|---|---|---|
scp |
One-time transfer | Simple, fast to use | No resume, sends all |
rsync |
Synchronization, backups | Fast, resumable, efficient | Needs installation |
sftp |
Interactive transfers | Familiar commands | Not ideal for automation |
β Conclusion
Now you know how to transfer files securely using SSH! Whether you’re copying a simple config file or syncing entire directories, there’s a tool for you.
- π’ Use
scpfor quick and occasional transfers - π Use
rsyncfor regular syncing and backups - π Use
sftpif you prefer a manual interface
Feel free to test these tools on a local network before using them in production!