NFS Overview
NFS (Network File System) enables different machines and operating systems to share data over a network. This allows applications on client systems to access files stored on remote servers as if they were local directories. NFS is particularly useful for Unix-like systems, providing a standardized method for disk file sharing across a network.
NFS Server Configuration on Ubuntu
Installing NFS Server
sudo apt-get install nfs-kernel-server
Configuring the NFS Export File
Edit the /etc/exports file to define which directories to share and which clients can access them:
sudo nano /etc/exports
Add an export entry with appropriaet options:
# /etc/exports format:
# shared_directory client_network(options)
# Example: Share /exports/project with the 192.168.100.0/24 network
/exports/project 192.168.100.0/24(rw,sync,no_root_squash,no_subtree_check)
# Example: Share /mnt/backup with all hosts (read-only)
/mnt/backup *(ro,sync,no_subtree_check)
Common options include:
rw: Read-write accessro: Read-only accesssync: Synchronous writesno_root_squash: Preserve root user privilegesno_subtree_check: Disable subtree checking
Restarting the NFS Service
After modifying the exports file, restart the NFS server to apply changes:
sudo /etc/init.d/nfs-kernel-server restart
Alternatively, you can use:
sudo systemctl restart nfs-kernel-server
Mounting NFS Shares on Clients
On the client machine, mount the shared directory using the mount command:
# Syntax: mount -t nfs server_ip:shared_directory local_mount_point
mount -t nfs 192.168.100.50:/exports/project /mnt/project
For automatic mounting on boot, add an entry to /etc/fstab:
192.168.100.50:/exports/project /mnt/project nfs defaults 0 0
Unmounting NFS Shares
When finished using the NFS share, unmount it to release resources:
umount /mnt/project
Secure File Transfer with SCP
SCP (Secure Copy) uses SSH protocol to transfer files secure between local and remote systems.
Prerequisites
Verify network connectivity and SSH access:
ping remote_server_ip
ssh username@remote_server_ip
Transferring Files from Remote to Local (Windows)
scp username@remote_server_ip:/remote/path/file.txt C:\local\directory\
For usernames containing backslashes (Windows domain accounts), escape them appropriately:
scp username@remote_server_ip:/remote/path/file.txt C:\local\directory\
Transferring Directories from Remote to Local (Windows)
scp -r username@remote_server_ip:/remote/path/directory C:\local\directory\
Transferring Files from Remote to Local (Ubuntu)
scp username@remote_server_ip:/remote/path/file.txt /local/directory/
Transferring Directories from Remote to Local (Ubuntu)
scp -r username@remote_server_ip:/remote/path/directory /local/directory/
Transferring Files from Local to Remote
scp /local/file.txt username@remote_server_ip:/remote/directory/
Transferring Directories from Local to Remote
scp -r /local/directory username@remote_server_ip:/remote/directory/
Additional SCP Options
-P: Specify custom SSH port (default is 22)-i: Specify private key file for authentication-v: Verbose mode for debugging-C: Enable compression during transfer
Example with custom port:
scp -P 2222 username@remote_server_ip:/remote/path/file.txt /local/directory/