Linux or UNIX securely copy files across a network computer

I know FTP is insecure, how do I securely copy files across a network computer? My network has Windows and Linux systems and how to copy files from one machine to another using ssh?

You need to use OpenSSH client and server technology to copy between two more networked computers. You can also find free ssh client tools. The scp command copies files between hosts on a network. It uses ssh for data transfer, and uses the same authentication and provides the same security as ssh.

ADVERTISEMENTS

Copy from Linux to Linux/UNIX system

The syntax is:
scp {source} {destination}
scp file1 file2
scp file1 user@host:/path/to/destination/

To copy file called data.txt to ras.nixcraft.in Linux system using vivek username:
$ scp data.txt vivek@ras.nixcraft.in:/home/vivek
Copy more than two files:
$ scp data.txt pic.jpg vivek@ras.nixcraft.in:/home/vivek
Copy /data directory and all files inside /data i.e. recursively copy entire directories:
$ scp -r /data/ vivek@ras.nixcraft.in:/home/vivek/
To copy a file from server2 to server1 while logged into server1:
scp vivek@server2:/my/file/location/ /path/to/destination

Copy from Windows to Linux/UNIX system

You can download any one of the following free Windows SCP client

Just install above client and follow on screen instructions to copy files.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
17 comments… add one
  • Todd Jul 11, 2007 @ 16:15

    Is there a way to copy multiple files to multiple servers? I’ve tried putting in a space and the location of the other server but no luck.

  • 🐧 nixCraft Jul 11, 2007 @ 19:01

    Todd,

    You can copy multiple files to multiple servers using shell for loop:

    SERVERS="user1@box1 user2@box2 user3@box3"
    for s in $SERVERS
    do
      scp file1 file2 ${s}:/path
    done
  • Raj Feb 13, 2008 @ 23:53

    you could also use it without a script.

    for i in 1 2 3; do scp file1 file2 user@box$i; done

  • Raj Feb 13, 2008 @ 23:55

    Actually it would be better if you could generate the ssh. keys and add it to your client machines.

  • Arun Mar 7, 2008 @ 5:45

    Is it possible to send password in the same line?
    As in ftp we use, user/password@host . We cant disturb the remote machine for moving public key files. Thats why.

  • module Nov 30, 2008 @ 11:51

    I found this
    http://toic.org/mscp/
    to be very helpful when you need to scp files to multiple hosts.

  • laurent Jun 12, 2009 @ 9:53

    Hi vivek,

    thank you for sharing all that in all the really goods post, article and tip/tricks. I’m not a sysadmin and your site has help me a lot those past moths for managing my server. Thanks !

  • D Nov 11, 2009 @ 15:45

    yes! very nice site !! thank you!

  • shashwat singh Feb 22, 2010 @ 9:31

    hi
    I am a new user to linux and just wanna noe how to share files in a network btw linux to linux machines or linux to windows
    hoping for some quick response

  • vishal Feb 25, 2010 @ 17:25

    When i try to copy a file from one server to another server using rcp command, i get error permission denied & if i use command scp, then it gives error connection lost whereas the server is pingable.

  • Shameem Jan 19, 2011 @ 14:00

    Hi All,

    This is all clear. But, if i want to copy single file to multiple destination using scp How can we do that ?

    If possible, Can anybody send me syntax for that.

    Thanks in advance.
    Best Regards,
    Shameem.

  • Kamal Jun 14, 2011 @ 6:25

    I connect to a network in three steps. Then how can I copy files to my machine home directory ?

  • nimi Aug 23, 2011 @ 7:08

    nice post thanks alot………:)

  • realrock Oct 4, 2011 @ 9:44

    source:root
    Dest:user account

    how copy a file from root mechine to user account in diff computer……..

  • Ratnam Oct 1, 2012 @ 6:39

    Hi

    i wanna copy a file from Linux to windows by using rdesktop please help me

    Thanks in advance

  • khaled shaaban Jul 23, 2013 @ 10:22

    Dears;

    We have a file xyz.cap in the below path in the LIGLIG01 of a Linux Server.
    I need to make a copy of this file into my flash memory or into my personal computer. Can you help please?

    LIGLIG01 tools# cd /tmp
    LIGLIG01 tmp# ls
    xyz.pcap rstser.sh tmpcmd.2638.out
    cfgsrv.lst savsl.tmp tmpcmd.2639.err
    hsperfdata_wali sec_audit.ptn1 tmpcmd.2639.out
    _iecs_soft1_prg.md5chk.old sec_audit.ptn2 tmpcmd.2643.err
    IRI-PTC_Y_TR00.pcap sec_audit_suroot.tmp tmpcmd.2643.out
    lig_cd_S21D_5.iso stunnel_conf_8329.conf W12C_5.iso
    netdos.out stunnel_conf_8401.conf _WALI_lig_soft.md5chk.old
    pid_stunnel_8329 stunnel_conf_8402.conf _WALI_wali_soft.md5chk.old
    pid_stunnel_8401 system.ini
    pid_stunnel_8402 tmpcmd.2638.err

    Thanks in advance.
    Best Regards;

  • Ankit Jan 21, 2016 @ 14:02

    How Can I make two windows machine communicate through command line (si I can yuse this concept in script) like scp can make communication between two linux system.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.