Sooner or later you need a file that lives on another machine. Linux offers several tools. Choose based on one question: do you want to copy files, or use them where they are?
Copying files
A copy gives you a separate file. Later changes on one side do not appear on the other.
scp copies over SSH:
$ scp report.txt [email protected]:/home/alice/
report.txt 100% 2048 1.1MB/s 00:00The colon separates the host from the path. Add -r to copy a directory. Note that scp uses -P, a capital letter, for a non-default port. Since OpenSSH 9.0, scp uses the SFTP protocol underneath by default.
sftp gives an interactive session with commands such as ls, get and put. rsync copies only what has changed, which suits repeated backups.
Sharing a filesystem
A network share lets a remote directory appear inside your own directory tree. Programs open files there as usual, and everyone connected sees the same data.
- NFS (Network File System) is common between Linux and Unix systems.
- Samba implements the SMB protocol, which Windows uses for file sharing. macOS and Linux can use it too.
Quick one-off downloads
Python can serve a directory over HTTP, so another machine fetches files with a browser or curl. It is convenient, but by default it has no encryption and no password.
Security first
Before sharing anything, decide:
- Who needs access, and from which addresses?
- Do they need to write, or only read?
- Is the network trusted?
SSH-based tools encrypt traffic and authenticate users, so they are a sensible default across untrusted networks. Do not expose NFS or SMB directly to the internet. Share only the directory that is needed, and stop temporary services afterwards.
Practise remote access in the networking and SSH lab.
Try it
- Create a file with
echo hello > note.txt. - If you have SSH access to a second machine, copy it there with
scp. - Run
sshto that machine and confirm the file withcat note.txt.
Check your understanding
File Sharing Overview
All 4 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.