Using Secure Copy

Secure copy is an extension of the SSH shell system that uses your PPK pair (if available) to copy files to and from remote systems. We already came across the scp command earlier when we copied our public key to a remote server.

The scp command is very similar to SSH in the way it defines what server you are connecting to (as well as supporting the [email protected] notation). The addition of a file, remote server, and location specification is what makes this command special.

scp myfile [email protected]:/etc/myfile

This command copies the file myfile to the server zen.palmcoder.net as the user Justin in the /etc/ directory. If you have a PPK defined, you will be prompted for that passphrase, as you would if you were logging in via SSH.

SCP is able to copy entire directories, as is the cp command. If the source file you specify to copy is, in fact, a directory, you need to add -r to the command line (before the specification on the source directory) for a recursive copy:

scp -r mydirectory [email protected]:/tmp/

This copies the entire contents of the directory mydirectory to the /tmp directory on zen.palmcoder.net as the user justin.

| f - - p Notice the colon used in the scp command. It is very important and tells SCP that

„■ *«■'-■ - ,t . you are, in fact, copying data to another machine. If you omit the colon, it will do a straight copy to [email protected] in our example.

Was this article helpful?

0 0

Post a comment