Yesterday we bowed for kings and bent our necks before emperors. But today, we kneel only to truth -- Khalil Gibran

  • Categories:
  • Syndication


  • Advanced

    Copying Files Over SSH with SCP

    SCP stands for “Secure Copy.” Basically, it’s used to copy files between machines securely. SCP operates over the SSH protocol; therefore, files that are copied between hosts are transferred as securely as transmissions over SSH itself. Unix-based machines running as SSH servers support scp by default. Windows can support it as well.

    A lot of you may be thinking that scp doesn’t have a lot of use when there is FTP. The first problem with FTP is that it’s not secure. Of course, there is SFTP, a secure version of FTP; however, that leads me to the second problem with FTP. I just don’t find it as quick to use (or SFTP, itself, for that matter) as scp. If you are comfortable with the command line, then scp is going to be a valuable resource.

    If you use “copy” or “cp” (depending on your OS) from the command line, then you will easily pick up scp. The full usage is as follows:

    scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
    [-l limit] [-o ssh_option] [-P port] [-S program]
    [[user@]host1:]file1 […] [[user@]host2:]file2

    Here’s the broken-down (basic) version:

    scp localfile user@host:directory/remotefile

    scp user@host:directory/remotefile localfile

    The first usage in the broken-down version copies a local file to a remote machine, and the second usage copies a remote file to the local machine. For example, if I wanted to copy “test.php” in the current directory on my local machine to the directory /www/myweb/testing on the remote web server, I would issue the following command:

    scp test.php helix@getoffthecomputer.com:/www/myweb/testing

    Running quickly through this command, from left-to-right: scp the file “test.php,” using the username “helix,” to “getoffthecomputer.com,” to the “www/myweb/testing” directory. Similarly, to copy “test.php” on the remote machine to /home/helix/myfiles on my machine, I would issue the following command:

    scp helix@brandonjaynes.com:/www/myweb/testing/test.php /home/helix/myfiles

    Whenever I’m doing some web design, I use scp to copy the local file to my web server to test. I also copy anything that I create locally that needs to go to my work through scp. The security that scp adds is just gravy. In all honesty, the best thing about scp is the ease of use. Rather than use FTP, cd to the right directory, change transfer formats, and put the file; I just copy as if I were copying to a disk on my local machine.

    As an added bonus, if you add the public key of your machine to the “authorized_keys2″ file of the remote machine, you don’t even have to log in when you scp. Issue the command, and the file is transferred, just like magic! If you have any questions or comments, or if you would like some help with getting your public key on your remote machine, drop me an email by clicking on the “Email” link at the top. Have fun!

    One Response to “Copying Files Over SSH with SCP”

    1. the life of justin moore » What I Use v2 Says:

      […] ment, allowing me to securely transfer files to remote servers. If you wanna know more, go read this. Vim - When I’m editing text, 9/10 t […]