在 Linux 服务器 上自建文件服务器,可以根据需求选择不同的方案。以下是几种主流的文件服务器搭建方式及其详细步骤:
方案 1:使用 Samba(适用于 Windows/Linux 文件共享)
Samba 服务器支持 Windows 共享协议(SMB/CIFS),适用于局域网文件共享,特别是 Linux 和 Windows 设备互传文件 的场景。
安装 Samba
sudo apt update
sudo apt install samba -y
创建共享目录
sudo mkdir -p /srv/samba/shared
sudo chmod 777 /srv/samba/shared
配置 Samba
修改 /etc/samba/smb.conf:
[global]
workgroup = WORKGROUP
security = user
[Shared]
path = /srv/samba/shared
browsable = yes
writable = yes
guest ok = yes
force user = nobody
创建 Samba 用户
sudo smbpasswd -a yourusername
启动 Samba 并设置开机自启
sudo systemctl restart smbd
sudo systemctl enable smbd
访问方式:
Windows 访问:\\\Shared
Linux 访问:smbclient ///Shared -U yourusername
方案 2:使用 FTP(适用于远程文件管理)
FTP 服务器适用于 公网或局域网文件共享,适合 批量上传/下载文件。
安装 FTP 服务器
sudo apt update
sudo apt install vsftpd -y
配置 FTP
修改 /etc/vsftpd.conf:
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
重启 FTP 服务
sudo systemctl restart vsftpd
sudo systemctl enable vsftpd
访问方式:
Windows/Linux:使用 FileZilla 或 ftp <服务器IP>
浏览器访问:ftp://<服务器IP>
以上是两种常见的方法,希望对你有用!