Facebook Twitter Instagram
    WiredRevolution.com
    • Home
    • About
    • Contact Us
    • Essential Linux Commands
    • Sitemap
    Facebook Twitter Instagram
    WiredRevolution.com
    commands

    Securely copy remote files with scp

    RyanBy RyanSeptember 27, 2008Updated:December 4, 20082 Mins Read
    Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Email

    scp allows you to securely copy files locally or remotely across a network. It uses SSH for data transfer and uses the same authentication. If you do not have public key authentication enabled you will be prompted for a password.

    This basic format for scp is this.

    scp [options] [[user@]src_host1:]file1 [[user@]dest_host2:]file2
    

    Assuming the remotehost has a username which matches username on the local host, this command will copy a a local file into the /tmp directory on remotehost. Notice that the colon separates the host from the location.

    $ scp file.txt remotehost:/tmp/
    

    You will be presented with the real-time statistics about the file transfer.

    $ scp file.txt remotehost:/tmp/
    
    file.txt                                      100%   22KB  21.9KB/s   00:00
    

    This command is similar but the period instructs the file to be placed in the users home directory.

    $ scp file.txt remotehost:.
    

    You can specify another user and login using their username. This will copy the file to ryan’s home directory.

    $ scp file.txt ryan@remotehost:.
    

    Alternatively you can copy a remote file to your local host. The period in the destination path refers to the current working directory in this case.

    $ scp ryan@remotehost:file.txt .
    

    Likewise, you can copy to any other local path you have access, such as the /tmp directory.

    $ scp ryan@remotehost:file.txt /tmp/
    

    Copying directories is similar except that the ‘-r’ option is required. This command will copy a directory from the current working directory to the users home directory on remotehost.

    $ scp -r mydir/ remotehost:.
    

    You can even copy from one remote host to another.

    $ scp remotehost1:file.txt remotehost2:file.txt
    

    Use the -p option to preserve modification times, access times, and modes from the original file.

    $ scp -p remotehost1:/tmp/file.txt remotehost2:/tmp/file.txt
    
    Share. Facebook Twitter Pinterest LinkedIn WhatsApp Reddit Email
    Previous ArticleControl search engine indexing with robots.txt
    Next Article How to take a screenshot in Linux using import

    Related Posts

    Transfer your ssh public key to a remote machine

    Fix git-upload-pack and git-receive-pack errors on shared hosting

    Setup SSH access between VirtualBox Host and Guest VMs

    Most Commented
    March 12, 2009

    Fix blue tinted video in Ubuntu

    September 10, 2010

    Setup SSH access between VirtualBox Host and Guest VMs

    March 8, 2011

    Install GNOME Shell in Ubuntu 10.10 Maverick

    April 4, 2009

    Setup the PS3 Bluetooth Controller on Ubuntu

    October 22, 2008

    How to correctly use LD_LIBRARY_PATH

    Recent Comments
    • Execute command on linux virtual machine (or server) from windows commandline on Setup SSH access between VirtualBox Host and Guest VMs
    • Solved: How to SSH to a VirtualBox guest externally through a host? - Daily Developer Blog on Setup SSH access between VirtualBox Host and Guest VMs
    • How to SSH to a VirtualBox guest externally through a host? [closed] – Code D3 on Setup SSH access between VirtualBox Host and Guest VMs
    • How to copy and paste from VirtualBox? [duplicate] on Setup SSH access between VirtualBox Host and Guest VMs
    • Jackie Laguna on Fix OpenGL: ChoosePixelFormat SketchUp error in WINE
    © 2025 ThemeSphere. Designed by ThemeSphere.

    Type above and press Enter to search. Press Esc to cancel.