Setup VPS for Linux Noobs!




new password?
login
X
SCP image

This tutorial shows how to copy files between Linux computers using Secure Copy & a command line interface. Fast, easy & safe, better than FTP or SFTP.

If you’re using Windows locally, skip to VPS Admin Part 11: Copy Website Files between Windows/Linux Computers using the CLI, ‘cos the method’s different.

If you’re after database backup, that’s different too, so check this out.

But for Linux-to-Linux file transfers, you’re in the right place, and whether local to remote machines, remote to local or remote to remote, Secure Copy is a super-fast program for transfers .. and the OpenSSH encryption protocol behind it means sensitive data is encrypted.

Setup Unmanaged VPS: The Ubuntu-Nginx Guide

Take your virtual private server from zero to hero

  .. from blank box to cute-as server ..  

with this easy-to-follow copy/paste guide.

22+ parts with video, here’s the index.

Just one prereq: you need the SSH (Secure Shell) protocol enabled on each machine. But hey, if you’ve just built or are looking to administer a remote server, that’s a must anyhow. If you’re not sure or want to sort that, read VPS Bible 3 – Setup PuTTY & VPS Bible 5 – PuTTY with OpenSSH.

Copy/Upload Linux Local TO Linux Remote

This first example will securely copy a local file to your remote user directory (ie, /home/user).

Logged into your shell, goto the local folder where the file to copy is located:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

And execute something like this:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

Chocks away.

Secure Copy Syntax Broken Down

  • scp starts the Secure Copy program
  • fileToCopy.txt is the file to upload
  • username is your remote Linux username
  • IP address is your remote IP address or hostname
  • : and don’t forget that!

.. that example presumes you’re using the default port, 22. If not – and you shouldn’t be * – specify another using this syntax:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. where -P (not -p) tells scp we’re using a bespoke port, and 54321 is the example port.

* To find out about changing your Nginx port, for added security, read VPS BIBLE Part 6: Harden the Secure Shell (SSH) & Create a Firewall.

Or if you want to copy a folder and its contents, try this:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. where the recursive command -r tells scp we’re copying a folder and it’s total content. Or:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. here we’re combining the recursive statement with the port.

If you want to change the filename from, say, abc.txt to xyz.txt, we can handle that:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. just add the revised filename to the end. Or, maybe you wanna change the folder path? Fussy, huh? ..


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. using the complete /path/to/folder and ensuring you’ve previously created the destination directory.

Finally, to preserve file timestamps and, if poss, the user, group and permissions, use this. I’ll example a folder and its contents, and put them in a specific folder:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. where the little p means preserve. Aha, so that’s why you gotta use the big P for port.

Top notch.

Copy/Backup Linux Local FROM Linux Remote

All the principles are the same, just the other way round.

So instead of:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. we syntax:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. where username@12.34.56.78:fileToCopy.txt specifies the file to copy from the remote host and fileToCopy.txt is the name we want to give the file, locally. We’ve previously cd‘ed to the directory into which we want to receive the file but, as with uploading, we could instead use a folder path. We could also preserve (p) the metadata and copy folders recursively.

To get a little more complicato:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. that says we want to copy the remote file abc.txt, specifying its location, but renaming it to xyz.txt in the specified folder which has been created previously. We’re not using port 21 so pinpoint the port 54321 with -P, and are preserving the files metadata with p.


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. this time, its basically the same, except we’re moving a folder and its content, so are employing the recursive, r, syntax.

Secure Copy Between Two Linux Hosts

Hmmn. Fact is, I dunno, cos I’ve not yet tried, so maybe someone can fill me in? Pretty please.

My guess would be something like:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. but really that is untested so, hey, be sure to play with mock files.

Right. Quite enough of that. You see the deal. This is powerful stuff, ideal for uploading/moving/backing up a site and, relative to SFTP or FTP, super-fast. Yup. Way quicker than opening FileZilla SnailZilla, wading through the ridiculously slow-loading directory tree, yaaawn, all that. You get the picture.

Setup Unmanaged VPS: The Ubuntu-Nginx Guide

Take your virtual private server from zero to hero

with this easy-to-follow copy/paste guide.

“My local PC runs Windows” Show me for Linux/Mac

22+ parts with video, here’s the index ..

Manage Unmanaged VPS: Ubuntu-Nginx Administration

Already set it up? We’d best maintain it then.

Toggle to the ..  Ubuntu-Nginx Admin Index

Manage Unmanaged VPS: Ubuntu-Nginx Administration

Maintain your virtual private server with ..

.. cheatsheets, tutorials, tips & guides.

Head back to the ..  Ubuntu-Nginx Installation Index

Nginx Admin: In the Works ..

This lot’s marked for addition already:-

  • Setup or Edit DNS using Bind
  • Network Tools Troubleshooting Guide
  • The Comprehensive Permissions Guide
  • Configuring Nginx Rewrites
  • Custom Website Error Page
  • Setting up Cron Jobs
  • Rsync for Incremental Remote-to-Local Backup
  • Cron & Rsync for Automatic Backup
  • Cron & mysqldump for Auto DB Backup
  • Safeguard Bandwidth with Hotlink Protection
  • Block Access with Nginx’ IP Deny



Got a Question? Want to Comment?

This site has no comments system. We've got a better system!

Please use the link at the top of the post and goto this topic's forum thread:-

  • to help build community
  • for a superior knowledge base
  • to keep info in one place, not diluted between forum & comments.

For those posts ported from Guvnr.com (pre-Feb/2010), archive comments remain.

Handy info from these comments is in the process of being ported to the forum and attributed to the original author.

If you think this idea sucks, let me know.

Thank you.

  • Secure VOIP communication with ZRTP | Intro to Voip Systems August 27th, 2009 at 8:28 pm

    [...] BACKUP/UPLOAD Website with Secure Copy SCP – VPS ADMIN #10 – GUVNR [...]

  • SECURE SSH KEY SETUP 4 LINUX: local-PC-to-remote-server: VPS BIBLE - vpsBible May 31st, 2010 at 8:09 am

    [...] SCP is the program Secure Copy, which you can read all about here – Backup or Upload with Secure Copy SCP (Linux/Linux) [...]