Moving files—such as backups, configuration files, web assets, and databases—between your local computer and a remote VPS (or between two remote cloud servers) is a daily task in system administration.
SCP (Secure Copy Protocol) allows you to securely copy files over an encrypted SSH connection using familiar cp syntax. In this tutorial, we cover practical SCP commands for managing your RivinCloud VPS.
1. Understanding SCP Syntax
The basic syntax follows the standard source and destination structure:
scp [options] [source] [destination]
A remote location is specified as:
username@hostname_or_ip:/path/to/remote/file
2. Common SCP Scenarios
Scenario A: Uploading a File from Local Machine to Remote VPS
scp mybackup.tar.gz ubuntu@192.0.2.10:/home/ubuntu/
Scenario B: Downloading a File from Remote VPS to Local Machine
scp ubuntu@192.0.2.10:/var/log/nginx/access.log ./downloads/
Scenario C: Uploading an Entire Directory Recursively (-r)
To copy an entire directory and all nested subdirectories:
scp -r ./my-website/ ubuntu@192.0.2.10:/var/www/html/
Scenario D: Transferring Between Two Remote Servers
You can initiate a direct transfer between two remote servers from your local terminal:
scp user1@server1.rivincloud.in:/backup.zip user2@server2.rivincloud.in:/restores/
3. Important Flags and Options
-P <port>: Specify a non-standard SSH port (Note: capital-Pinscp, lowercase-pinssh).scp -P 2222 backup.tar.gz ubuntu@192.0.2.10:/home/ubuntu/-i <key_path>: Specify a private SSH key file.scp -i ~/.ssh/id_rsa backup.sql ubuntu@192.0.2.10:/home/ubuntu/-C: Enable compression on the fly, speeding up transfers over slower internet connections.scp -C largefile.iso ubuntu@192.0.2.10:/home/ubuntu/-q: Quiet mode (disables the progress meter, useful in cron jobs).
Common Mistakes
- Using lowercase
-pfor port:scp -ppreserves file modification times; use capital-Pto designate a port number. - Forgetting
-rwhen copying folders: Attemptingscp /myfolder user@host:/dirwithout-rwill returnnot a regular file. - Target folder permissions: If the destination folder requires
rootprivileges (like/var/www/or/etc/), transfer the file to/home/username/first, then SSH in andsudo mvit.
Troubleshooting
- Permission Denied (publickey): Ensure the specified key path (
-i) is correct and permissions on~/.ssh/id_rsaare600. - Connection Timed Out: Verify the server IP and check if UFW firewall allows SSH on your specified port.
Best Practices
[!TIP] For very large directory transfers (gigabytes of small files), compress them with
tar -czvffirst, transfer the single archive withscp, and decompress remotely. This is much faster than transferring thousands of small files individually.
- For syncing directories incrementally, consider
rsync -avzPas an alternative that resumes interrupted transfers.
Frequently Asked Questions
Is SCP deprecated?
While OpenSSH now uses SFTP/SSH behind the scenes for modern SCP implementations, scp remains the quickest, most universal CLI tool for one-off file copies.
Can SCP resume a paused or interrupted transfer?
No. If an SCP transfer is interrupted, it must restart from the beginning. Use rsync --partial if you need resume capabilities.
Conclusion
SCP provides a fast, secure, and encrypted method for transferring assets to and from your RivinCloud VPS. Keep this cheatsheet handy for all your file migration needs!
