Dreams of Thought

Are dreams thoughts… or are thoughts dreams..

RSS Feed

Copying files from one unix box to another with scp

Posted by Anirudh on July 31, 2009 at 11:23 AM

ssh is a very powerful and widely used protocol in all the Unices. If you’ve used the ssh client in your Unix/Linux box, you must have realised how indispensable it is. There is another indispensable tool that uses the ssh protocol – scp (secure copy). scp was meant to be an alternative to unsecure tools like rcp. It has since replaced most such programs. Since scp uses the ssh protocol, the encryption it uses ensures security of your data.

Using scp is simple. It works almost like the regular cp command. The basic syntax is
In order to specify the SOURCE or DESTINATION we have a special syntax.
[email protected]:PATH

Let me give you an example :
$scp [email protected]:/var/www/html/test.html [email protected]:~/test_dir/
Copy /var/www/html/test.html in the machine called “box” as user “anirudh” to the box called “linux” as user “gingerjoos” to the path HOMEDIR/test_dir/

That’s it :) Simple, right?

To copy the file to our localmachine, we could do this
$scp [email protected]:/var/www/html/test.html ~/workarea/

This would copy the file test.html in the machine called “box” (as user anirudh) to the localmachine at path HOMEDIR/work_area/

Interchange the source-destination to copy file in your localmachine to the remote machine.

If you want to copy whole directories, use the ‘-r’ flag(recursive copy)
$scp -r ~/workarea/ [email protected]:~/workdir/

Since scp is tied to the ssh program, the keys you use to set up passwordless login with ssh works for scp as well.

Got questions? Got something to add to this? Post your comments below :)

Filed under Linux, technology
Tagged as , , , ,
You can leave a comment, or trackback from your own site.


  • On September 10, 2009 at 8:37 PM Sreekanth said

    We have a software to do scp from windows.

    Winscp its open source.

  • On September 10, 2009 at 10:34 PM Anirudh said

    Yup, there are other scp/ssh clients available for windows too. Filezilla and putty come to mind.

  • On January 22, 2010 at 12:51 PM Jain Johny said

    I have one more point to add.

    Do not use scp when your source contains hard/soft links and you want to copy them as it is. Instead of links, scp will copy the actual file to destination. You will end up copying 1.2TB instead of 600GB as what happened to me a few months back. (In my case, I had actual files and symlinks to them in the source directory). If you have links, use rsync.


  • On January 23, 2010 at 10:11 PM Anirudh said

    Thanks Jain. Will keep that in mind

  • On October 13, 2012 at 2:05 AM Meghana` said

    Thanks this was useful!

  • On July 1, 2013 at 4:56 PM Aamir said

    I want a script to run on windows. It will connect 1 unix box, select a file and transfer it to another unix box. Do you have any idea how i can do it?

  • On July 5, 2013 at 12:57 PM neetu said

    i tried the command like this

    scp -r [email protected]:/u02/cream/Lev1/cndb/db [email protected]:/u02/cream/Lev1/cndb/db
    but it didnt worked out i recived the error

    Permission denied (gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive).
    lost connection

    while the password provided was correct.

    kinldy advice.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Pingbacks / Trackbacks