[root@localhost ~]# yum install samba
[root@localhost ~]# systemctl start smb
[root@localhost ~]# systemctl status smb
● smb.service - Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2018-03-13 15:18:47 CST; 2s ago
Main PID: 2340 (smbd)
[root@localhost ~]# systemctl enable smb
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
[root@localhost ~]# systemctl status smb
● smb.service - Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2018-03-13 15:18:47 CST; 1min 33s ago
[root@localhost ~]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section “[homes]”
Processing section “[printers]”
Processing section “[print$]”
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
[root@localhost ~]# useradd manager
[root@localhost ~]# passwd manager
[root@localhost ~]# usermod -L manager
[root@localhost ~]# smbpasswd -a manager
[root@localhost ~]# useradd employee
[root@localhost ~]# passwd employee
[root@localhost ~]# usermod -L employee
[root@localhost ~]# smbpasswd -a employee
创建共享目录share
[root@localhost ~]# mkdir -p /samba/share && chmod -R +777 /samba/share
[root@localhost ~]# ls -ldZ /samba/share
drwxrwxrwx. root root unconfined_u:object_r:default_t:s0 /samba/share
selinux给共享目录授权
[root@localhost ~]# chcon -t samba_share_t /samba/share/
[root@localhost ~]# ls -ldZ /samba/share
drwxrwxrwx. root root unconfined_u:object_r:samba_share_t:s0 /samba/share
创建管理者目录managers
[root@localhost ~]# mkdir -p /samba/managers && chmod -R +777 /samba/managers
[root@localhost ~]# ls -ldZ /samba/managers
drwxrwxrwx. root root unconfined_u:object_r:default_t:s0 /samba/managers
[root@localhost ~]# chcon -t samba_share_t /samba/managers/
[root@localhost ~]# ls -ldZ /samba/managers
drwxrwxrwx. root root unconfined_u:object_r:samba_share_t:s0 /samba/managers
创建职工目录employees
[root@localhost ~]# mkdir -p /samba/employees && chmod -R +777 /samba/employees
[root@localhost ~]# ls -ldZ /samba/employees
drwxrwxrwx. root root unconfined_u:object_r:default_t:s0 /samba/employees
[root@localhost ~]# chcon -t samba_share_t /samba/employees/
[root@localhost ~]# ls -ldZ /samba/employees
drwxrwxrwx. root root unconfined_u:object_r:samba_share_t:s0 /samba/employees
打开home目录
[root@localhost ~]# setsebool -P samba_enable_home_dirs on
[root@localhost ~]# setsebool -P samba_domain_controller on
配置用户读写权限
[root@localhost ~]# cp /etc/samba/smb.conf /etc/samba/smb.conf.copy
[root@localhost ~]# vim /etc/samba/smb.conf
[share]
comment = Share Directories
path = /samba/share
valid users = manager,employee
browseable = Yes
read only = No
[managers]
comment = Managers Directories
path = /samba/managers
valid users = manager
browseable = Yes
write list = manager
[employees]
comment = Employees Directories
path = /samba/employees
valid users = manager,employee
browseable = Yes
write list = manager,employee
[root@localhost ~]# systemctl restart smb
打开防火墙
[root@localhost ~]# firewall-cmd –zone=public –add-port=137/udp –permanent
success
[root@localhost ~]# firewall-cmd –zone=public –add-port=138/udp –permanent
success
[root@localhost ~]# firewall-cmd –zone=public –add-port=139/tcp –permanent
success
[root@localhost ~]# firewall-cmd –zone=public –add-port=445/tcp –permanent
success
[root@localhost ~]# firewall-cmd –reload
success
访问文件系统:\ip地址
[root@topscience ~]# yum -y install samba-client
[root@topscience smb]# smbclient //localhost/share -U账号%密码
Try “help” to get a list of possible commands.
smb: >
137、138 为 UDP 端口,通过网上邻居传输文件时使用的端口。139 通过这个端口进入的连接试图获得 NetBIOS/SMB 服务。NetBIOS 协议常被用于 Windows 文件、打印机共享和 Samba。
无法访问某些端口 阿里云默认屏蔽端口
现象:ECS 实例监听了对应端口,但这个端口在部分地区无法访问,而其它端口访问正常的情况。
分析:部分运营商判断端口 135、139、444、445、5800、5900 等为高危端口,默认被屏蔽。
解决:建议您修改敏感端口为其它非高危端口承载业务。