04. Secure Copying Files scp

Perhaps you only need to upload or download a file from a host, and want the added security features of SSH. We can do so with the scp command.

Transferring Simple Files

To upload a file, type the command, followed by the file to transfer, then the location.

$ scp sample.txt user@host.edu:

Remember to tack on the colon at the end - otherwise you'll find that you simply made a copy of sample.txt in your current directory called user@host.edu!

To copy it back to your current directory, simply swap the targets around.

$ scp user@host.edu:sample.txt sample.txt

You'll notice that the path following the colon is relative to the home directory (since that's where you are logged in when you ssh into a host).

$ scp sample.txt user@host.edu:Documents/sample.txt

If you want to copy somewhere other than within your home directory, pass an absolute path after the colon.

$ scp init.d user@host.edu:/etc/init.d

Copying entire directories

To copy entire directories, pass the -r option. Additionally, you can pass in the -p option to preserve the timestamps and permission settings.

$ scp -rp mail user@host.edu

Aching back from coding all day?

Self-Massage Tool

Aching back from coding all day? Try Back Problems

Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.

$ Check price
29.9529.95Amazon 4.5 logo(3,443+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

System Admin Handbook

Take your Linux skills to the next level! Try Linux & UNIX

This book approaches system administration in a practical way and is an invaluable reference for both new administrators and experienced professionals. It details best practices for every facet of system administration, including storage management, network design and administration, email, web hosting, scripting, and much more.

$ Check price
74.9974.99Amazon 4.5 logo(142+ reviews)

More Linux & UNIX resources