在linux中,有多种方法可以共享文件夹资源。以下是一些常用的方法:
Samba是一个开源软件,允许linux系统与Windows系统共享文件和打印机。
sudo apt update
sudo apt install samba
/etc/samba/smb.conf
:sudo nano /etc/samba/smb.conf
在文件末尾添加以下内容:
[shared_folder]
path = /path/to/your/folder
available = yes
valid users = @sambashare
read only = no
browsable = yes
public = yes
writable = yes
将 /path/to/your/folder
替换为你想要共享的文件夹路径。
3. 创建Samba用户:
sudo adduser sambashare
sudo smbpasswd -a sambashare
输入并确认密码。 4. 重启Samba服务:
sudo systemctl restart smbd
NFS(Network File System)允许linux系统之间共享文件。
sudo apt update
sudo apt install nfs-kernel-server
/etc/exports
文件:sudo nano /etc/exports
添加以下内容:
/path/to/your/folder 192.168.1.0/24(rw,sync,no_subtree_check)
将 /path/to/your/folder
替换为你想要共享的文件夹路径,192.168.1.0/24
替换为你的网络IP范围。
3. 导出共享目录:
sudo exportfs -a
sudo systemctl restart nfs-kernel-server
SSHFS允许你通过SSH协议挂载远程文件系统。
sudo apt update
sudo apt install sshfs
sshfs username@remote_host:/path/to/remote/folder /path/to/local/mount_point
将 username
替换为远程主机的用户名,remote_host
替换为远程主机的IP地址或域名,/path/to/remote/folder
替换为远程文件夹路径,/path/to/local/mount_point
替换为你本地想要挂载的文件夹路径。
3. 卸载远程文件夹:
fusermount -u /path/to/local/mount_point
FTP(File Transfer Protocol)和SFTP(Secure File Transfer Protocol)用于文件传输。
sudo apt update
sudo apt install vsftpd
/etc/vsftpd.conf
文件:sudo nano /etc/vsftpd.conf
确保以下行未被注释:
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
sudo systemctl restart vsftpd