Master Linux File Sharing: SCP, Rsync, HTTP Server, NFS & Samba Explained
This guide walks you through multiple Linux file‑sharing techniques—including SCP, Rsync, a simple Python HTTP server, NFS, and Samba—detailing when to use each method, the required commands, configuration steps, and practical tips for reliable cross‑machine transfers.
1. Overview of File Sharing
When you need to move data between computers on the same network, a USB drive can work but is often inconvenient; network‑based file sharing provides a faster, more flexible solution. Below are several common Linux tools for copying files or synchronizing directories across hosts.
2. Using scp
scp(secure copy) works like cp but transfers files over SSH, inheriting SSH authentication and encryption.
Copy from local to remote
$ scp myfile.txt [email protected]:/remote/directoryCopy from remote to local
$ scp [email protected]:/remote/directory/myfile.txt /local/directoryCopy an entire directory
$ scp -r mydir [email protected]:/remote/directory3. Using rsync
rsyncalso transfers files over SSH but uses a delta‑algorithm to send only changed parts, which saves bandwidth and resumes interrupted transfers.
Common options:
V – verbose output
r – recursive (process directories)
h – human‑readable numbers
z – compress data during transfer
Sync two local directories
$ rsync -zvr /local/directory/one /local/directory/twoCopy from remote to local
$ rsync /local/directory [email protected]:/remote/directoryCopy from local to remote
$ rsync [email protected]:/remote/directory /local/directory4. Simple HTTP Server (Python)
Python can quickly expose a directory via HTTP, useful for ad‑hoc sharing. $ python -m SimpleHTTPServer Access the share from another machine using http://IP_ADDRESS:8000 or, on the same host, http://localhost:8000.
5. NFS (Network File System)
NFS is the standard Linux network file‑sharing protocol, allowing a server to export directories that clients can mount.
Start NFS client and mount a share
$ sudo service nfsclient start
$ sudo mount server:/directory /mount_directoryAutomatic mounting For persistent mounts, edit /etc/fstab . If the server is unavailable at boot, the mount can delay or fail; using an automounter avoids this problem.
6. Samba (CIFS/SMB)
Samba implements the Windows SMB/CIFS protocol on Linux, enabling file and printer sharing with Windows machines.
Creating a Samba Share
Install Samba $ sudo apt install samba Edit /etc/samba/smb.conf to define the shared path and permissions.
Set a Samba password for a user $ sudo smbpasswd -a [username] Create the directory to share $ mkdir /my/directory/to/share Restart the Samba service
$ sudo service smbd restartAccessing the Share
From Windows, use \\HOST\sharename in the Run dialog. From Linux, you can mount the share with:
$ sudo mount -t cifs servername:directory /mountpoint -o user=username,pass=passwordAlternatively, the smbclient command line tool lets you browse and transfer files:
$ smbclient //HOST/directory -U userConclusion
Choosing the appropriate file‑sharing method for your workflow can dramatically improve efficiency and reduce friction when moving data between machines.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
