|
8 | 8 | - Ubuntu:`dpkg -l | grep samba` |
9 | 9 |
|
10 | 10 | - 安装: |
11 | | - - CentOS 6:`XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX` |
| 11 | + - CentOS 6:`yum install samba samba-client samba-common` |
12 | 12 | - Ubuntu:`sudo apt-get install -y samba samba-client` |
13 | 13 |
|
14 | 14 | ## Samba 服务器配置文件常用参数 |
15 | 15 |
|
16 | | -- 配置文件介绍(记得先备份):`sudo vim /etc/samba/smb.conf` |
| 16 | +- 配置文件介绍(记得先备份 `cp /etc/samba/smb.conf /etc/samba/smb.conf.backup`):`sudo vim /etc/samba/smb.conf` |
17 | 17 | - 该配置解释: |
18 | | - - 在 [globle] 区域 |
19 | | - - workgroup = WORKGROUP #WORKGROUP表示Windows默认的工作组名称,一般共享给windows是设置为WORKGROUP |
| 18 | + - 在 [global] 区域 |
| 19 | + - workgroup = WORKGROUP #WORKGROUP表示Windows默认的工作组名称,一般共享给windows是设置为WORKGROUP,此字段不重要,无需与 Windows 的域保持一致 |
20 | 20 | - security = user #ubuntu下配置文件默认没有这句,这个是自己填上去的。表示指定samba的安全等级,安全等级分别有四种:share(其他人不需要账号密码即可访问共享目录)、user(检查账号密码)、server(表示检查密码由另外一台服务器负责)、domain(指定Windows域控制服务器来验证用户的账号和密码) |
| 21 | + 注: samba 4 不再支持 security = share (查看版本 smbd --version) |
21 | 22 | - 在新区域区域 |
22 | 23 | - 当 security = share 使用下面这段,这段自己添加的,其中myshare这个名字表示其他机子访问该分享地址时用:file://该服务机IP/myshare |
23 | 24 | ``` |
|
33 | 34 | ``` |
34 | 35 | [myshare2] |
35 | 36 | comment = share for users |
36 | | - path = /opt/mysamba2 #分享的目录,其中这个目录需要chmod 777 /opt/mysamba权限 |
| 37 | + path = /opt/mysamba2 #分享的目录,其中这个目录需要chmod 777 /opt/mysamba权限(不一定要 777 权限,只要登录 samba 的用户是这个目录的用户即可,那么在 Windows 中的文件创建和写入都等同于 linux 的等价账户) |
37 | 38 | browseable = yes |
38 | 39 | writable = yes |
39 | 40 | public = no |
| 41 | + read only = no |
| 42 | + guest ok = no # samba 4 拥有的 |
| 43 | + create mask = 0646 |
| 44 | + force create mode = 0646 |
| 45 | + directory mask = 0747 |
| 46 | + force directory mode = 0747 |
40 | 47 | ``` |
| 48 | +
|
| 49 | + - 一份成功的 samba 4 配置 |
| 50 | + [global] |
| 51 | + workgroup = WORKGROUP |
| 52 | + passdb backend = tdbsam |
| 53 | + printing = cups |
| 54 | + printcap name = cups |
| 55 | + printcap cache time = 750 |
| 56 | + cups options = raw |
| 57 | + map to guest = Bad User |
| 58 | + include = /etc/samba/dhcp.conf |
| 59 | + logon path = \\%L\profiles\.msprofile |
| 60 | + logon home = \\%L\%U\.9xprofile |
| 61 | + logon drive = P: |
| 62 | + max connections = 0 |
| 63 | + deadtime = 0 |
| 64 | + max log size = 500 |
| 65 | +[share1] |
| 66 | + path = /home/<your path> |
| 67 | + browsable =yes |
| 68 | + writable = yes |
| 69 | + read only = no |
| 70 | + guest ok=no |
| 71 | + create mask = 0646 |
| 72 | + force create mode = 0646 |
| 73 | + directory mask = 0747 |
| 74 | + force directory mode = 0747 |
| 75 | +
|
41 | 76 | - 启动服务: |
42 | 77 | - `sudo service samba restart` |
| 78 | + - `systemctl start smb.service` # 启动 samba |
| 79 | + - `service smb restart` # 启动 samba |
| 80 | + - `systemctl enable smb.service` # 激活 |
| 81 | + - `systemctl status smb.service` # 查询 samba 状态(启动 samba 前后可以用查询验证) |
| 82 | +
|
| 83 | +
|
| 84 | +## Samba 登录及验证 |
| 85 | +
|
| 86 | +- 在 Windows 连接 Samba 之前,可在本地(linux)使用命令验证 |
| 87 | +
|
| 88 | + `smbclient –L //localhost/<your samba share label> -U <your samba user>` |
| 89 | + 接下来输入的 password 来自于 `pdbedit -a user1` 命令为该用户设置的密码,不一定是 linux 用户密码 |
| 90 | + <your samba share label> 来自 `/etc/samba/smb.conf` 文件中的标签,如上面的例子中有 `//localhost/myshare2` |
| 91 | +
|
| 92 | + 提示如下面,表示 Samba 服务启动成功 |
| 93 | + ``` |
| 94 | + Domain=[xxx1] OS=[Windows 6.1] Server=[Samba 4.6.2] |
| 95 | + |
| 96 | + Sharename Type Comment |
| 97 | + --------- ---- ------- |
| 98 | + share1 Disk |
| 99 | + IPC$ IPC IPC Service (Samba 4.6.2) |
| 100 | + Domain=[xxx1] OS=[Windows 6.1] Server=[Samba 4.6.2] |
| 101 | + |
| 102 | + Server Comment |
| 103 | + --------- ------- |
| 104 | + |
| 105 | + Workgroup Master |
| 106 | + --------- ------- |
| 107 | + xxx2 xxx1 |
| 108 | + WORKGROUP xxx3 |
| 109 | + |
| 110 | + ``` |
| 111 | +- Windows 登录 |
| 112 | + 打开资源管理器 -> 映射网络驱动器 -> 文件夹 填写上述 `smbclient –L` 命令后面加的路径 -> |
| 113 | + 弹出用户名密码对话框 -> 登录成功 |
| 114 | +
|
| 115 | +
|
| 116 | +## Samba 登录失败 |
| 117 | +
|
| 118 | +- linux 防火墙 |
| 119 | +
|
| 120 | +- Windows 用户密码都正确,错误提示‘未知的用户名和密码。’ |
| 121 | + regedit 打开注册表,删除键值 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa 中的 LMCompatibilityLevel,无需重启计算机 |
43 | 122 |
|
44 | 123 | ## Samba 资料 |
45 | 124 |
|
46 | 125 | - <http://www.lvtao.net/linux/555.html> |
47 | 126 | - <https://www.centos.bz/2011/07/centos5-install-samba-windows-linux-fileshare/> |
48 | 127 | - <https://wsgzao.github.io/post/samba/> |
49 | 128 | - <http://linux.vbird.org/linux_server/0370samba.php> |
| 129 | +- <https://www.liberiangeek.net/2014/07/create-configure-samba-shares-centos-7/> |
| 130 | +- <https://superuser.com/questions/1125438/windows-10-password-error-with-samba-share> |
| 131 | +- <https://github.com/SeanXP/README.md/tree/master/samba> |
| 132 | +- <http://www.apelearn.com/bbs/study/23.htm> |
0 commit comments