root@ann ~]# rpm -qa | grep samba samba-client-libs-4.10.16-15.el7_9.x86_64 samba-common-4.10.16-15.el7_9.noarch samba-common-libs-4.10.16-15.el7_9.x86_64 samba-libs-4.10.16-15.el7_9.x86_64 samba-4.10.16-15.el7_9.x86_64 samba-common-tools-4.10.16-15.el7_9.x86_64 samba-client-4.10.16-15.el7_9.x86_64
如果没有安装,有两种方式可以安装:
yum install -y samba
useradd test1
创建 Smb 用户,此用户必须是 Linux 上已经建立的,输入密码,完成即可。
[root@ann ~]# smbpasswd -a test1 New SMB password: Retype new SMB password: Added user test1.
可用pdbedit命令查看是否创建成功
[root@ECS-N4 ~]# pdbedit -L test1:1003:
拓展:
修改samba用户的密码
$sudo smbpasswd 用户名
禁用samba用户
$sudo smbpasswd -d 用户名
启用samba用户
sudo smbpasswd -e 用户名
删除samba用户
$sudo smbpasswd -x 用户名
也可用pdbedit的相关命令
setenforce 0
[root@localhost ~]# cat /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. # SELINUX=enforcing SELINUX=disabled # SELINUXTYPE= can take one of three two values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
[global] workgroup = SAMBA security = user passdb backend = tdbsam printing = cups printcap name = cups load printers = yes cups options = raw smb ports = 4455 [share] comment = share web site code path = /www/wwwroot browseable = yes writeable = yes public = yes guest ok = yes
由于阿里云可能对samba端口号445给封掉,因此将端口号重定向到4455
5. 开放防火墙端口:
firewall-cmd --zone=public --add-port=139/tcp --permanent firewall-cmd --zone=public --add-port=445/tcp --permanent firewall-cmd --zone=public --add-port=137/udp --permanent firewall-cmd --zone=public --add-port=138/udp --permanent firewall-cmd --reload systemctl restart firewalld.service
验证新增加端口是否生效(实际测试中4455并没开)
[root@ann ~]# firewall-cmd --zone=public --query-port=139/tcp yes [root@ann ~]# firewall-cmd --zone=public --query-port=445/tcp yes [root@ann ~]# firewall-cmd --zone=public --query-port=4455/tcp no
service smbd restart
8.可现在linux上测试一下是否成功
8.本地Windows端修改端口号
通过第三方工具,进行端口映射(来源https://github.com/Arno0x/DivertTCPconn)
可以直接在网盘下载
链接:https://pan.baidu.com/s/1O7UHotdXDYgHr_WzNqvkRg
提取码:uhfq
下载完成后,利用管理员权限运行cmd,cd至文件夹目录下,运行命令
divertTCPconn.exe 445 4455
如图,则运行成功:会一直卡着,不能关掉,关掉映射就不成功了
divertTCPconn 445 4455 Usage: divertTCPconn original_dstport new_dstport [disablechecksum] [debug] Usage: divertTCPconn original_dstport new_dstport [disablechecksum] [debug]
9.映射网络驱动器
右键“此电脑” --> “映射网络驱动器” --> 输入“\你的服务器ip\share” --> 点击完成: 注意:share和/etc/samba/samba.conf中的[share]对应,可以起别的名字
10.弹出登陆界面:
输入samba用户名和密码,登陆成功
11.在Windows上可能涉及SMB服务和防火墙等权限问题,需要进行一下设置
安装SMB服务
原文链接:https://blog.csdn.net/Di_Wong/article/details/103841718