这是一个困扰我整整一天的问题。我的环境如下:
- 运行 Windows 7(64 位)
- 使用 VirtualBox 5 以 Linux guest 身份运行 CentOS 7
我一直在寻找在 CentOS 来宾中创建 Samba 共享的解决方案,因此我能够从我的 Windows 7 主机系统访问正在运行的 CentOS 来宾中的文件夹。
我将 VirtualBox 配置为使用两个网络适配器(NAT 和 Host-Only)。
我在 CentOS 客户机上安装了 Samba,并将其配置为独立服务器。我创建了一个名为“数据”的 Samba 共享。在此处查看完整的 smb.conf,Samba 共享在文件末尾定义:
[global]
workgroup = WORKGROUP
server string = Samba Server Version %v
dns proxy = no
# log files split per-machine:
log file = /var/log/samba/log.%m
# maximum size of 50KB per log file, then rotate:
max log size = 50
security = user
passdb backend = tdbsam
load printers = yes
cups options = raw
server role = standalone server
encrypt passwords = true
guest ok = yes
usershare allow guests = yes
obey pam restrictions = yes
unix password sync = yes
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
pam password change = yes
map to guest = bad user
#============================ Share Definitions ==============================
[homes]
comment = Home Directories
browseable = no
writable = yes
; valid users = %S
; valid users = MYDOMAIN\%S
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes
[data]
comment = Data Folder
path = /data
guest ok = yes
browseable = yes
create mask = 0777
directory mask = 0777
writable = yes
force create mode = 777
force directory mode = 777
force security mode = 777
force directory security mode = 777
此 Samba 配置适用于 Ubuntu 14.04。 VirtualBox 来宾操作系统完美。但无论我做什么,这个配置在 CentOS 中都不起作用。当我尝试使用 \\centos-guest\data\ 从 Windows 主机访问 Samba 共享时,我总是收到“权限被拒绝”错误
事实证明,问题是正在运行的防火墙和 SELinux(安全增强型 Linux)。要禁用两者,请在 CentOS 中执行以下步骤:
- systemctl 停止防火墙
- systemctl 禁用 firewalld
- vi /etc/selinux/配置
[global]
workgroup = WORKGROUP
server string = Samba Server Version %v
dns proxy = no
# log files split per-machine:
log file = /var/log/samba/log.%m
# maximum size of 50KB per log file, then rotate:
max log size = 50
security = user
passdb backend = tdbsam
load printers = yes
cups options = raw
server role = standalone server
encrypt passwords = true
guest ok = yes
usershare allow guests = yes
obey pam restrictions = yes
unix password sync = yes
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
pam password change = yes
map to guest = bad user
#============================ Share Definitions ==============================
[homes]
comment = Home Directories
browseable = no
writable = yes
; valid users = %S
; valid users = MYDOMAIN\%S
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes
[data]
comment = Data Folder
path = /data
guest ok = yes
browseable = yes
create mask = 0777
directory mask = 0777
writable = yes
force create mode = 777
force directory mode = 777
force security mode = 777
force directory security mode = 777
之后,重新启动来宾操作系统,您就可以在 Windows 主机上访问 CentOS 来宾的 samba 共享。
但请注意,您在 Linux 来宾操作系统上禁用了防火墙!
如果这不是您想要的,您应该寻找替代方法。