环境

  • samserver 10.15.3.42
  • samclient 10.15.3.100

服务端&&客户端

1.新建共享文件夹,并赋权

[root@sambserver ~]# mkdir -p /datab/common
[root@sambserver ~]# cd /datab/
[root@sambserver datab]# chmod 777 common/

2.安装samba服务端

[root@sambserver ~]# yum install samba -y

3.自定义共享目录,配置/etc/samba/smb.conf文件,写入common目录共享

[root@sambserver ~]# vi /etc/samba/smb.conf
[root@sambserver ~]# tail /etc/samba/smb.conf
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775

[common]
comment = gonggong
path = /datab/common
writeable = yes
browsable = yes

3.查看状态

[root@sambserver ~]# netstat -antp |grep smbd
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 373/smbd
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 373/smbd
tcp6 0 0 :::139 :::* LISTEN 373/smbd
tcp6 0 0 :::445 :::* LISTEN 373/smbd

4.新建账户

[root@sambserver  ~]# useradd -s /sbin/nologin smbser  # 将linux系统用户设为samba用户,并按照提示设置密码
[root@sambserver ~]# pdbedit -a smbser
new password:
retype new password:
Unix username: smbser
NT username:
Account Flags: [U ]
User SID: S-1-5-21-2348822856-2243297598-2784838519-1000
Primary Group SID: S-1-5-21-2348822856-2243297598-2784838519-513
....
[root@sambserver ~]# pdbedit -L # 读取当前samba用户列表
smbser:1001:

5.查看samba共享文件,默认是samba用户的家目录

[root@sambclient ~]# smbclient -U smbser -L //10.15.3.42
Enter SAMBA\smbser's password:

Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
common Disk gonggong ##自定义共享文件夹目录
IPC$ IPC IPC Service (Samba 4.10.16)
smbser Disk Home Directories ##samba用户家目录
Reconnecting with SMB1 for workgroup listing.

Server Comment
--------- -------

Workgroup Master
--------- -------

6.客户端client 登录查看共享文件(用户家目录)

[rootsambclient ~]# smbclient -U smbser //10.15.3.42/smbser
Enter SAMBA\smbser's password:
Try "help" to get a list of possible commands.
smb: \>

7.客户端client 登录查看共享文件(自定义空间)

[rootsambclient ~]# smbclient -U smbser //10.15.3.42/common
Enter SAMBA\smbser's password:
Try "help" to get a list of possible commands.
smb: \>

8.开机自启

[root@sambserver ~]# systemctl daemon-reload #重新加载服务文件
[root@sambserver ~]#systemctl start smb
[root@sambserver ~]#systemctl enable smb

9.查看配置是否正确

[root@sambserver ~]# testparm
Load smb config files from /etc/samba/smb.conf
Loaded services file OK.

挂载

1.client端新建挂载点pro_common,根目录下创建 pro_common

[root@client ~]# mkdir /pro_common

2.永久挂载,编辑client端fstab文件,重启服务器查看挂载情况

[root@client ~]# vim /etc/fstab ##添加挂载内容
//10.15.3.42/common /pro_common cifs defaults,username=smbser,password=1234

测试

1.查看client端挂载的共享文件夹,新建测试文件

[root@client ~]# cd /pro_common/
# 新建测试文件aaa
[root@client ~]# touch aaa
# 查看当前文件列表
[root@nues pro_common]# ls
aaa

2.在server服务端查看测试文件

[root@sambserver ~]# cd /datab/
[root@prometheus datab]# ls
common
[root@sambserver datab]# cd common/
[root@sambserver common]# ls
aaa