1、安装Samba
yum -y install smb
或: yum -y install samba
2、验证Samba服务是否正确安装:
rpm -qa | grep smb
3、启动SMB服务
方式一:
systemctl start smb(启动smb)
systemctl restart smb(重启smb)
systemctl stop smb (关闭smb)
systemctl status smb(显示Samba的状态)
方式二:
service start smb(启动smb)
service restart smb(重启smb)
service stop smb (关闭smb)
service status smb(显示Samba的状态)
4、创建共享目录并更改文件夹权限:
此处创建了共享目录public,同时共享目录public及其上级目录(根目录/)都要设置用户权限
· mkdir /public
· chmod 777 /public
· chmod 777 /
5、添加samba账户
· smbpasswd -a root (将存在的系统用户添加进去)
补充:
查看samba账户 pdbedit -L
删除samba账户 pdbedit -x username
添加用户 pdbedit -a usernamete
pdbedit -a username:新建Samba账户。
pdbedit -r username:修改Samba账户。
pdbedit -x username:删除Samba账户。
pdbedit -L:列出Samba用户列表,读取passdb.tdb数据库文件
6、配置文件smb.conf
· vi /etc/samba/smb.conf
(配置文件原内容如下所示!)
[global]
workgroup = WORKGROUP
passdb backend = tdbsam
printing = cups
printcap name = cups
printcap cache time = 750
cups options = raw
map to guest = Bad User
include = /etc/samba/dhcp.conf
logon path = \%L\profiles.msprofile
logon home = \%L%U.9xprofile
logon drive = P:
usershare allow guests = Yes
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[public]
comment = test smb
path = /pubic
browseable = yes
read only = no
writable = yes
public = yes
7、重启samba服务 每次修改完必须重启
· service smb restart
· service smb status
8、测试配置文件smb.conf是否正确
· testparm
9、windows上验证
打开计算机——地址栏输入服务器地址
10、映射网络驱动器
我的电脑——菜单栏“映射网络驱动器”——逐步完成
11、如果无法访问共享目录可能是centos的selinux安全保护的影响,此时最好将selinux关闭。SELinux一共有3种状态,分别是Enforcing,Permissive和Disabled状态。第一种是默认状态,表示强制启用,第二种是宽容的意思,即大部分规则都放行。第三种是禁用,即不设置任何规则。
方法一:修改selinux的配置文件,永久关闭selinux
先执行vim /etc/selinux/config命令 将SELINUX=enforcing改为SELINUX=disabled
接着:reboot重启linux,使得配置文件生效
方法二:临时关闭selinux:setenforce 0
然后再查看selinux的当前状态:
getenforce
配置文件二:(亲测有效)
See smb.conf.example for a more detailed config file or
read the smb.conf manpage.
Run ‘testparm’ to verify the config is correct after
you modified it.
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
[root_users_share]
comment=root_share
path=/disk
read only = No
writable = yes
browseable = Yes
create mask = 0777
directory mask = 0777
[zhuanghao]
comment = zhuanghao
path = /root/zhuanghao
read only = No
writable = yes
browseable = Yes
create mask = 0777
directory mask = 0777
[global]
ntlm auth = yes