Use scp to securely transfer files

OpenSSH is a great tool for remotely logging in to other computers in a secure manner and then being able to use them from anywhere around the world. What the ssh command doesn't offer you normally however is a way to securely transfer files between your local machine and the remote machine.

That's where scp comes in. It stands for Secure Copy and piggybacks off the SSH infrastructure to send files to move files to and from the two machines. scp is a standard part of the OpenSSH suite, so it should be available almost everywhere.

It's also pretty simple to use. The basic syntax is as follows. To transfer a local file to a remote server, you will do something a bit like this:

$ scp ~/localfile user@remotehost:/remote/directory/file

This will copy the file localfile in your home folder to /remote/directory/file on the server. Once you hit enter, you'll be asked for your SSH password or passphrase as you would in a normal SSH session.

To reverse the process and copy a remote file to your system, simply reverse the two file operands.

$ scp user@remotehost:/remote/directory/file ~/localfile

That's basically it, it is a very simple tool to use. You will get a nice progress meter complete with download/upload speeds as the file gets transferred and once the deed is done, you'll be dropped back to your shell.

There are, of course, more advanced options if you have a complex setup (for example -p portnumber for alternative ports), which you can read up on by using the man page.

Avatar for peter Peter Upfold -

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Use scp to securely transfer files

Home » Articles » Use scp to securely transfer files