Debian 文件共享实用指南
在 Debian 上,常用且稳定的文件共享方式包括:Samba(跨平台,Windows/ Linux/ macOS)、NFS(Linux/Unix 同网段)、SSHFS(基于 SSH 的安全挂载),以及虚拟机场景的 VirtualBox 共享文件夹。下面给出可直接执行的配置步骤与要点。
Samba 共享步骤
sudo apt update && sudo apt install sambasudo mkdir -p /srv/share && sudo chmod 0775 /srv/share/etc/samba/smb.conf[share]
path = /srv/share
browseable = yes
read only = no
valid users = alice,bob
create mask = 0644
directory mask = 0755
sudo adduser alicesudo smbpasswd -a alicesudo systemctl restart smbd nmbdsudo systemctl enable smbd nmbdsudo ufw allow samba\\<服务器IP>\sharesmb://<服务器IP>/sharesudo systemctl status smbdsudo journalctl -u smbdNFS 共享步骤
sudo apt update && sudo apt install nfs-kernel-server nfs-commonsudo mkdir -p /srv/nfs/shared && sudo chmod 0755 /srv/nfs/shared/etc/exports/srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check)
sudo exportfs -arvsudo systemctl restart nfs-kernel-serversudo ufw allow proto tcp from any to any port 111,2049sudo ufw allow proto udp from any to any port 111,2049sudo mount -t nfs <服务器IP>:/srv/nfs/shared /mnt/nfs_sharedSSHFS 用户态挂载步骤
sudo apt update && sudo apt install sshfssudo mkdir -p /mnt/sshfssshfs user@remote_host:/path/to/remote /mnt/sshfsfusermount -u /mnt/sshfs虚拟机场景 VirtualBox 共享文件夹
sudo mount -t vboxsf share /mnt/share/host:/share /mnt/share vboxsf defaults,uid=<你的用户ID>,gid=<你的组ID> 0 0 加入 /etc/fstab方法选择与安全建议