欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

samba配置详解

程序员文章站 2022-05-17 18:04:53
...

安装samba应用
yum -y install samba samba-client
启动Samba应用
systemctl start smb nmb
•查看Samba服务进程
[aaa@qq.com ~]# ps -ef | grep -E ‘smb|nmb’
root 9885 1 0 14:48 ? 00:00:00 /usr/sbin/nmbd
root 9887 1 0 14:48 ? 00:00:00 /usr/sbin/smbd
root 9888 9887 0 14:48 ? 00:00:00 /usr/sbin/smbd
root 9889 9887 0 14:48 ? 00:00:00 /usr/sbin/smbd
root 9890 9887 0 14:48 ? 00:00:00 /usr/sbin/smbd
root 9959 9627 0 15:02 pts/0 00:00:00 grep –color=auto -E smb|nmb
•查看Samba应用服务端口
smbd应用进程主要监听139和445端口, nmbd应用进程主要监听137与138端口。
[aaa@qq.com ~]# netstat -tunlp | grep -E ‘smbd|nmbd’
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 9887/smbd
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 9887/smbd
tcp6 0 0 :::139 :::* LISTEN 9887/smbd
tcp6 0 0 :::445 :::* LISTEN 9887/smbd
udp 0 0 192.168.6.255:137 0.0.0.0:* 9885/nmbd
udp 0 0 192.168.6.186:137 0.0.0.0:* 9885/nmbd
udp 0 0 0.0.0.0:137 0.0.0.0:* 9885/nmbd
udp 0 0 192.168.6.255:138 0.0.0.0:* 9885/nmbd
udp 0 0 192.168.6.186:138 0.0.0.0:* 9885/nmbd
udp 0 0 0.0.0.0:138 0.0.0.0:* 9885/nmbd
3 配置Samba服务
1.服务规划
◦系统分区时,单独划分一个/media/storage的分区,分区下有logger和shared两个文件夹;shared文件夹/storage/shared下对应的管理员账号为administrator,用户账户号为shared;
2.创建文件夹和用户
◦创建文件夹

创建文件夹

[aaa@qq.com storage]# cd /media/storage
[aaa@qq.com storage]# mkdir shared
[aaa@qq.com storage]# ls
drwxr-xr-x. 2 root root 6 Aug 3 10:12 shared

◦创建用户

创建用户

[aaa@qq.com storage]# useradd -s /sbin/nologin administrator
[aaa@qq.com storage]# useradd -g administrator -s /sbin/nologin shared
◦建立Samba用户
[aaa@qq.com storage]# smbpasswd -a administrator
New SMB password: test
Retype new SMB password: test
Added user admin.
[aaa@qq.com storage]# smbpasswd -a shared
New SMB password:
Retype new SMB password:
Added user shared.
◦更改目录属性
[aaa@qq.com storage]# chown administrator.administrator shared
[aaa@qq.com storage]# chmod -R 777 shared
3.配置Samba服务
[aaa@qq.com storage]# vi /etc/samba/smb.conf
[global]
workgroup = WORKGROUP
server string = Samba Server Version %v
netbios name = Linux-Server
log file = /var/log/samba/%m.log
max log size = 1024
security = user
passdb backend = tdbsam

[shared]
comment = Shared Directories
path = /media/storage/shared/
public = no
browseable = yes
writable = yes
create mask = 0777
directory mask = 0777
force directory mode = 0777
force create mode = 0777
修改完Samba配置文件后,需要重启Samba服务配置(systemctl start smb nmb)
关闭防火墙:systemctl stop firewalld.service
查询防火墙状态:firewall-cmd –state
才能生效……
Administrator/test登陆后,发现右键鼠标创建文件或者文件夹,会弹出提示框:
samba配置详解

经过搜索,最后发现问题出在selinux上,linux系统默认启用了selinux导致其他机器访问linux的文件系统时被拒绝,解决办法很简单:
命令行下输入:setenforce 0 回车即可。
或者也可以修改selinux的配置文件:
vi /etc/selinux/config,在配置文件中进行如下设置即可:
samba配置详解
但是,这样修改之后需要重启操作系统才能生效。如果还是连接不上,很有可能是防火墙的问题,在命令行下执行:
service iptables stop,即可恢复。

建议修改/etc/rc.d/rc.local,每次重启需重启smb/nmb服务

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/usr/sbin/apachectl start
/etc/rc.d/init.d/mysqld start
/etc/rc.d/init.d/smb start
/usr/local/subversion/bin/svnserve -d
/usr/bin/systemctl stop firewalld.service
相关标签: samba