背景
最近部署的EMBY需要使用其他服务器的文件夹,故需要创建共享文件夹
步骤
Ubuntu想要创建共享文件夹需要安装samba
,其他Ubuntu服务器想要挂载该共享文件夹需要安装cifs-utils
Ubuntu创建共享文件夹
1)安装samba
apt install samba
2)编辑 /etc/samba/smb.conf
末尾增加配置
[share]
path=/home/share
available=yes
browseable=yes
public=yes
writable=no
参数说明:
[share]
为自定义共享的名称
path
为创建共享的文件路径
available
用来指定该共享资源是否可用,no则不可用
browseable
为设置共享是否可浏览,如果no就表示隐藏,需要通过IP+共享名称进行访问
public
为共享是否允许guest账户访问,如不需要,用#注释掉即可,#注释掉之后,可以实现无密码访问
writable
共享文件是否可写可选参数
writable
= yes/no #设置共享是否具有可写权限
read only
= yes/no #设置共享是否具有只读权限
4)创建samba账号
在 /etc/samba/下创建一个名为smbpasswd的文件
touch /etc/samba/smbpasswd
创建一个名为test【自定义】的samba账号
smbpasswd - a test
输入两次密码,完成创建samba账户
注:这个test【自定义】的用户名需要是你的Ubuntu系统的用户,否则会报错 Failed to add entry for user
如果没有相应的系统用户,可以通过一下命令添加
groupadd test -g 6000
useradd test -u 6000 -g 6000 -s /sbin/nologin -d /dev/null
5)重启samba服务
对配置进行了更改后,需要重启samba服务才会生效
service smbd restart
6) 设置防火墙
ufw allow from xxx.xxx.xxx.xxx to any port 445
ufw allow from xxx.xxx.xxx.xxx to any port 139
ufw reload
Ubuntu挂载共享文件夹
1)安装cifs-utils
apt install cifs-utils
2)挂载共享文件夹
mount -t cifs //xxx.xxx.xxx.xxx/share /home/data -o username=test,password=你的密码
参数说明:
//xxx.xxx.xxx.xxx/share
为共享的文件夹
/home/data
挂载到本地的文件夹
username
用户名
password
密码
完成挂载
3)取消挂载共享文件夹
umount /home/data
设置开机挂载
1)完善rc-local.service服务
vi /lib/systemd/system/rc-local.service
添加以下内容
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
2)添加/etc/rc.local文件
创建文件
touch /etc/rc.local
在/etc/rc.local文件里面输入要运行的shell命令
#!/bin/sh
mount -t cifs //xxx.xxx.xxx.xxx/share /home/data -o username=test,password=你的密码
添加可执行权限
chmod +x /etc/rc.local
3)设置开启启动rc-local服务
执行systemctl enable rc-local.service
即可
评论