ubuntu_samba部署

由于之前装过samba但是被我稀里糊涂一顿操作给卸载了,显然也没有卸干净,于是打算重装一下。把能踩的坑基本都踩了。

首先我由于之前手动删除了 /etc/samba文件夹,导致重新下载以后这个文件夹不会自动生成。因此我需要删除samba所依赖的所有相关包:

1
sudo apt-get remove samba*

重新安装后还是会出现错误:dpkg:处理 samba-common (--configure)时出错:

因此要这样操作:

1
2
3
4
5
6
sudo` `mv` `/var/lib/dpkg/info` `/var/lib/dpkg/info_old
sudo` `mkdir` `/var/lib/dpkg/info
sudo` `apt-get update, apt-get -f ``install
sudo` `mv` `/var/lib/dpkg/info/``* ``/var/lib/dpkg/info_old
sudo` `rm` `-rf ``/var/lib/dpkg/info
sudo` `mv` `/var/lib/dpkg/info_old` `/var/lib/dpkg/info

然后就有/etc/samba 文件夹,但是smb.conf文件仍然需要自己配置:
其中,[share] 是自定义的,里面的path指向我需要共享的文件夹。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Global parameters
[global]
log file = /var/log/samba/log.%m
logging = file
map to guest = Bad User
max log size = 1000
obey pam restrictions = Yes
pam password change = Yes
panic action = /usr/share/samba/panic-action %d
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
passwd program = /usr/bin/passwd %u
server role = standalone server
server string = %h server (Samba, Ubuntu)
unix password sync = Yes
usershare allow guests = Yes
idmap config * : backend = tdb


[printers]
browseable = No
comment = All Printers
create mask = 0700
path = /var/spool/samba
printable = Yes


[print$]
comment = Printer Drivers
path = /var/lib/samba/printers


[share]
comment = this is Linux share directory
guest ok = Yes
path = /home/jason/sharefile

然后,要运行

1
smbpasswd -a root

来设置root用户,否则samba无法启动

设置完以后,我尝试启动samba服务:sudo system restart smbd.service ,结果失败:Failed to restart smbd.service: Unit smbd.service is masked

需要如下配置:

1
2
3
sudo systemctl unmask smbd.service
sudo systemctl enable smbd.service
sudo systemctl restart smbd.service

成功启动samba服务

-------------本文结束,感谢您的阅读-------------