Skip navigation

Tag Archives: ssh

A little gem I learned today when needing to get a file from a remote system that I’d sshed into onto my local machine so that I could manipulate it while offline: the scp command.

There are a lot of switches for scp, but if you’re trying to get a file to or from a remote machine, or even between two remote machines, both of which you are able to ssh into, here’s the syntax:

scp -P 22 [user@source.machine.address.if.remote:]/directory/of/file/to/copy [user@target.machine.if.remote:]/target/directory

In the above example, the -P flag is indicating the port (in this case, we’re using port 22 because we’re logging in using ssh).

If you’ve typed everything correctly, you’ll then be prompted for the password of the user at the remote machine (or the first one, if you’re moving files between two remote machines). After entering everything correctly, you should see a new line indicating the current file being transferred, the percentage transferred (this will update live), number of bytes transferred, transfer speed, and elapsed time. If you’re just copying a small text file, this will flash by faster than you can really comprehend, and you’ll be deposited back at the command prompt before you know it.