重启防火墙
sudo ufw disable //关闭防火墙sudo ufw enable //开启 sudo ufw status //查看防火墙状态
安装
sudo apt-get install samba
sudo apt-get install smbclient
sudo apt-get install daemon
sudo apt-get install libtalloc2
配置
打开Samba配置文件:
sudo vim /etc/samba/smb.conf
在其最后添加:
[share]path = /home/zhangtao/share //此目录为共享目录路径,请根据实际情况修改available = yesbrowseable = yespublic = yeswritable = yes
创建共享目录
mkdir ~/share
chmod 777 ~/share
创建Samba用户
sudo touch /etc/samba/smbpasswd
sudo smbpasswd -a zhangtao
根据提示输入用户密码(登陆Samba共享目录的时候需要).
重启Samba
sudo /etc/init.d/samba restart
开启Ubuntu的Samba服务器的端口
这一步刚开始的没有意识到,然后就是windows一直无法访问:命令如下所示
sudo ufw allow 137/udp
sudo ufw allow 138/udp
sudo ufw allow 139/tcp
sudo ufw allow 445/tcp
结果如下为正常
taozhang@taozhang-virtual-machine:~/share$ sudo ufw allow 137/udp
规则已添加
规则已添加 (v6)
taozhang@taozhang-virtual-machine:~/share$ sudo ufw allow 138/udp
规则已添加
规则已添加 (v6)
taozhang@taozhang-virtual-machine:~/share$ sudo ufw allow 139/tcp
规则已添加
规则已添加 (v6)
taozhang@taozhang-virtual-machine:~/share$ sudo ufw allow 445/tcp
规则已添加
错误处理
配置上述之后,正常就可以访问samba了,如果访问不了,可以查看下/var/log/samba/目录下的log.%m文件内容,里边记录了具体的错误,我遇到的错误如下所示
[2019/12/08 18:32:17.137859, 0] ../source4/smbd/server.c:372(binary_smbd_main)samba version 4.3.11-Ubuntu started.Copyright Andrew Tridgell and the Samba Team 1992-2015
[2019/12/08 18:32:17.159113, 0] ../source4/smbd/server.c:477(binary_smbd_main)At this time the 'samba' binary should only be used for either:'server role = active directory domain controller' or to access the ntvfs file server with 'server services = +smb' or the rpc proxy with 'dcerpc endpoint servers = remote'You should start smbd/nmbd/winbindd instead for domain member and standalone file server tasks
[2019/12/08 18:32:17.159187, 0] ../lib/util/become_daemon.c:111(exit_daemon)STATUS=daemon failed to start: Samba detected misconfigured 'server role' and exited. Check logs for details, error code 22
看到上面的Log 输出failed的地方有个daemon,猜想是不是daemon没有安装,于是用下面命令安装了该软件:
sudo apt-get install daemon
sudo apt-get install libtalloc2
如果已经安装了这两个软件可以尝试重新安装下
sudo apt-get install --reinstall daemon
sudo apt-get install --reinstall libtalloc2
然后重新启动后神奇般就可以访问samba共享目录了