Ubuntu安装samba
1、安装samba
sudo apt install samba
2、配置文件
打开配置文件 /etc/samba/smb.conf
sudo vim /etc/samba/smb.conf
移动到最后一行(shift+g
可快速到达)
/******** 解释 ********/
[ubuntu_samba]
comment = ubuntu samba dir #说明
path = /home/samba #共享的 samba #目录
available = yes #允许访问
browseable = yes #可以浏览
public = yes #公开
writable = yes #可写
create mask = 0755 #当外部创建新文件时的权限
security = share #共享模式
force user = root #在外部添加新文件时, 文件的所有者
arm force group =root #在外部添加新文件时, 文件的所在组
/******** 实际写入 ********/
[ubuntu_samba]
comment = arm ubuntu samba dir
path = /home/samba
available = yes
browseable = yes
public = yes
writable = yes
create mask = 0755
security = share
force user = root
arm force group =root
3、配置用户账号:
创建 Samba 用户账号(与系统用户账号分离):
sudo smbpasswd -a username
其中,username
是要创建的 Samba 用户名。将被要求设置密码。
将 Samba 用户添加到共享目录的访问权限中。
找到共享目录的配置段,在其中添加以下行,以授予特定用户访问权限
valid users = username
4、重启 Samba 服务:
运行以下命令以重新启动 Samba 服务,以使配置生效
sudo service smbd restart
常见问题
增加samba用户提示Failed to add entry for user
[root@ubuntu ~]# smbpasswd -a test
New SMB password:
Retype new SMB password:
Failed to add entry for user test.
解决办法:
这是因为没有加相应的系统账号,所以会提示Failed to add entry for user的错误,只需增加相应的系统账号test就可以了:
[root@ubuntu ~]# groupadd test -g 6000
[root@ubuntu ~]# useradd test -u 6000 -g 6000 -s /sbin/nologin -d /dev/null
这时就可以用smbpasswd -a test增加test这个samba账号了!为了增加系统的安全性,所以加的系统账号不要给shell它,也不给它指定目录,到时在/home目录给test账号建个文件夹,该文件夹只有test有读写权限即可!
如:
[root@ubuntu ~]# mkdir /home/test
[root@ubuntu ~]# chown -R test:test /home/test
若不想让另人访问,只让test用户可以访问,只需执行命令:
[root@ubuntu ~]# chmod u+rwx,g+rwx,o-rwx /home/test
这时可以用smbpasswd命令增加samba账号test了
[root@ubuntu ~]# smbpasswd -a test
New SMB password:
Retype new SMB password:
Added user test.
参考文章1: Ubuntu安装Samba服务Ubuntu安装Samba服务
参考文章2: Ubuntu与window实现文件共享——Samba使用
参考文章2: 增加samba用户提示Failed to add entry for user