1.安装服务器包
[root@centos8:~]#
yum -y install samba
[root@centos8:~]#
systemctl enable --now smb #端口号为445和1392.创建相关共享目录,创建登录账号(samba的虚拟用户必须是操作系统账号转化而来,)
[root@centos8:~]#useradd smb1
[root@centos8:~]#将系统账号转化为samba账号
smbpasswd -a smb1
New SMB password:
Retype new SMB password:
Added user smb1.
[root@centos8:~]#查看当前的账号
pdbedit -L
smb1:1001:
[root@centos8:~]#useradd smb2
[root@centos8:~]#
smbpasswd -a smb2
New SMB password:
Retype new SMB password:
Added user smb2.
[root@centos8:~]#
pdbedit -L
smb1:1001:
smb2:1002:
#smb账号存放在/var/lib/samba/private/passdb.tdb数据库文件中3.修改配置文件,设置共享目录和写权限
[root@centos8:~]#mkdir /www
[root@centos8:~]#touch /www/a.txt
[root@centos8:~]#vim /etc/samba/smb.conf
[www]path=/www #[share1]只是个名字,具体位置由path指定writable=yes #samba共享服务开启写权限[root@centos8:~]#chmod777 /www/ #文件系统添加写权限。[root@centos8:~]#
systemctl restart smb
3.客户端测试
[root@centos7:~]#
smbclient -L 10.0.0.8 -U smb1%123456
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
share1 Disk
IPC$ IPC IPC Service (Samba 4.14.5)
smb1 Disk Home Directories
Reconnecting with SMB1 for workgroup listing.
smbXcli_negprot_smb1_done: No compatible protocol selected by server.
protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE
Unable to connect with SMB1 -- no workgroup available
[root@centos7:~]#
smbclient //10.0.0.8/share1 -U smb1%123456
Try "help" to get a list of possible commands.
smb: \>ls. D 0 Fri Jun 1719:34:16 2022.. D 0 Fri Jun 1719:33:35 2022
a.txt N 0 Fri Jun 1719:34:16 202252403200 blocks of size 1024. 52004800 blocks available
smb: \> get a.txt #下载
getting file\a.txt of size 0 as a.txt (0.0 KiloBytes/sec)(average 0.0 KiloBytes/sec)
smb: \>!ls
anaconda-ks.cfg a.txt
smb: \> put anaconda-ks.cfg #上传
putting file anaconda-ks.cfg as \anaconda-ks.cfg (220.3 kb/s)(average 220.3 kb/s)
smb: \>ls. D 0 Fri Jun 1719:50:11 2022.. D 0 Fri Jun 1719:33:35 2022
a.txt N 0 Fri Jun 1719:34:16 2022
anaconda-ks.cfg A 1579 Fri Jun 1719:50:11 202252403200 blocks of size 1024. 52004796 blocks available