samba服务是构建在NetBOIS协议上的
samba服务可以提供打印机服务,如下图
初步测试 security = share
[root@paly ~]#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 "[temp]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
[global]
workgroup = MYGROUP
server string = Samba Server Version %v
log file = /var/log/samba/log.%m
max log size = 50
client signing = required
idmap config * : backend = tdb
cups options = raw
[homes]
comment = Home Directories
read only = No
[printers]
comment = All Printers
path = /var/spool/samba
printable = Yes
print ok = Yes
browseable = No
[temp]
comment = test from temp
path = /tmp
read only = No
guest ok = Yes
[root@paly ~]#smbclient -L //127.0.0.1
-bash: smbclient: command not found
yum install -y samba-client
[root@paly ~]#/etc/init.d/smb restart
Shutting down SMB services: [ OK ]
Starting SMB services: [ OK ]
[root@paly ~]#/etc/init.d/nmb restart
Shutting down NMB services: [ OK ]
Starting NMB services: [ OK ]
[root@paly ~]#smbclient -L //127.0.0.1
Enter root's password:
Anonymous login successful
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-53.el6_10]
Sharename Type Comment
--------- ---- -------
homes Disk Home Directories
temp Disk test from temp
IPC$ IPC IPC Service (Samba Server Version 3.6.23-53.el6_10)
Anonymous login successful
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-53.el6_10]
Server Comment
--------- -------
PALY Samba Server Version 3.6.23-53.el6_10
Workgroup Master
--------- -------
MYGROUP
[root@paly ~]#mount -t cifs //127.0.0.1/temp /mnt/test/
mount: wrong fs type, bad option, bad superblock on //127.0.0.1/temp,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount.<type> helper program)
In some cases useful info is found in syslog - try
dmesg | tail or so
[root@paly ~]#sudo yum install -y cifs-utils samba-client
[root@paly ~]#mount -t cifs //127.0.0.1/temp /mnt/
Password:
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) #挂载出错
[root@paly ~]#dmesg | tail #查看日志
CIFS VFS: cifs_mount failed w/return code = -13
Status code returned 0xc000006d NT_STATUS_LOGON_FAILURE
CIFS VFS: Send error in SessSetup = -13
CIFS VFS: cifs_mount failed w/return code = -13
Status code returned 0xc000006d NT_STATUS_LOGON_FAILURE
CIFS VFS: Send error in SessSetup = -13
CIFS VFS: cifs_mount failed w/return code = -13
Status code returned 0xc000006d NT_STATUS_LOGON_FAILURE
CIFS VFS: Send error in SessSetup = -13
CIFS VFS: cifs_mount failed w/return code = -13
[root@paly ~]#testparm | grep security
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 "[temp]"
WARNING: The security=share option is deprecated
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
security = SHARE
[root@paly ~]#mount -t cifs //127.0.0.1/temp /mnt/
Password: #share 模式下不设密码直接回车
[root@paly ~]#
[root@paly ~]#df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg_ton-lv_root
18968492 9207512 8797344 52% /
tmpfs 254048 0 254048 0% /dev/shm
/dev/sda1 487652 54836 407216 12% /boot
//127.0.0.1/temp 18968492 9207512 8797344 52% /mnt
设置 security = user
[root@paly home]#chgrp tang /home/paly/
[root@paly home]#chmod 2770 /home/paly/
[root@paly home]#ll -d /home/paly/
drwxrws--- 2 root tang 4096 Mar 25 22:16 /home/paly/
#重启smb,nmb服务
[root@paly home]#pdbedit -a -u tom1 #输入设置密码
[root@paly home]#smbclient -L //127.0.0.1 -U tom1
Enter tom1's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-53.el6_10]
Sharename Type Comment
--------- ---- -------
tom_test Disk show test info
IPC$ IPC IPC Service (Samba Server Version 3.6.23-53.el6_10)
tom1 Disk Home Directories
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-53.el6_10]
Server Comment
--------- -------
PALY Samba Server Version 3.6.23-53.el6_10
Workgroup Master
--------- -------
MYGROUP PALY
[root@paly home]#mount -t cifs //127.0.0.1/tom1 /mnt -o username=tom1 #挂载测试
Password:
[root@paly mnt]#cd /home/tom1
[root@paly tom1]#touch test.txt
[root@paly tom1]#cd /mnt/
[root@paly mnt]#ls
test.txt
#两个目录有相同的文件,相关日志在message中查看
[root@paly ~]#umount /mnt #umount 失败
umount: /mnt: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@paly ~]#w
23:32:35 up 14:50, 2 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
tom pts/0 192.168.31.62 19:25 29:51 0.13s 0.06s sshd: tom [priv]
tom pts/1 192.168.31.62 23:18 0.00s 0.09s 0.05s sshd: tom [priv]
[root@paly ~]#pkill -kill -t pts/0
[root@paly ~]#umount /mnt #再次umount成功
[root@paly ~]#
配置磁盘配额
[root@paly test]#repquota -av
*** Report for user quotas on device /dev/sda5
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root +- 51220 10000 10000 none 3 3 0
tom ++ 15360 1024 15360 none 4 3 4 none
tom1 -- 0 1024 15360 0 3 4
tom2 -- 0 1024 15360 0 3 4
Statistics:
Total blocks: 8
Data blocks: 1
Entries: 4
Used average: 4.000000
win端连接linux端共享
powershell上对SMB1
协议进行操作
Get-SmbServerConfiguration | Select EnableSMB1Protocol, EnableSMB2Protocol #查看协议配置的当前状态
Set-SmbServerConfiguration -EnableSMB1Protocol $false #禁用 SMBv1
Set-SmbServerConfiguration -EnableSMB1Protocol $true #启用 SMBv1
windows上启SMB 1.0/CIFS文件共享支特,安装重启,后
可以看到成功登录上tom1的smb服务器
tom_test
为tang组共享目录,且tang为tom1的属组。tom1
目录为tom1用户的主目录,可在配置文件中配置开放或关闭。
Linux端连接win端共享
[root@paly ~]#smbclient -L //192.168.31.62 -U tom #查询tom用户的网络共享数据
Enter tom's password:
Domain=[TOM] OS=[Windows 10 Education 19044] Server=[Windows 10 Education 6.3]
Sharename Type Comment
--------- ---- -------
ADMIN$ Disk 远程管理
C$ Disk 默认共享
D$ Disk 默认共享
E$ Disk 默认共享
F$ Disk 默认共享
G$ Disk 默认共享
IPC$ IPC 远程 IPC
print$ Disk 打印机驱动程序
share_test Disk
Users Disk
session request to 192.168.31.62 failed (Called name not present)
session request to 192 failed (Called name not present)
session request to *SMBSERVER failed (Called name not present)
NetBIOS over TCP disabled -- no workgroup available
[root@paly ~]#nmblookup -U 192.168.31.62 tom #查询NetBIOS与ip信息 ,后面两个解析是虚拟机ip
querying tom on 192.168.31.62
192.168.31.62 tom<00>
192.168.40.1 tom<00>
命令行访问
[root@paly home]#smbclient '//192.168.31.62/share_test' -U tom
Enter tom's password:
Domain=[TOM] OS=[Windows 10 Education 19044] Server=[Windows 10 Education 6.3]
smb: \> dir
. DR 0 Mon Mar 28 18:01:14 2022
.. DR 0 Mon Mar 28 18:01:14 2022
desktop.ini AHS 46 Sat Mar 26 22:21:49 2022
新建文本文档.txt A 0 Mon Mar 28 18:01:14 2022
64032 blocks of size 4194304. 17455 blocks available
smb: \> put /home/test.py
NT_STATUS_ACCESS_DENIED opening remote file \/home/test.py
smb: \> get desktop.ini
getting file \desktop.ini of size 46 as desktop.ini (22.5 KiloBytes/sec) (average 22.5 KiloBytes/sec)
smb: \> exit
直接挂载
[root@paly ~]#mount -t cifs //192.168.31.62/share_test /mnt/smb_test -o username=tom,password=0000,codepage=cp936 #挂载到/mnt/smb_test
[root@paly ~]#cd /mnt/smb_test/
[root@paly smb_test]#ls
desktop.ini
[root@paly smb_test]#ca desktop.ini
-bash: ca: command not found
[root@paly smb_test]#cat desktop.ini
[ViewState]
Mode=
Vid=
FolderType=Generic
[root@paly smb_test]#ls
desktop.ini 新建文本文档.txt
[root@paly smb_test]#
codepage #远程主机的编码方式,cp936为中文
iocharset #本机语言编码方式 utf8
[root@paly smb_test]#mount
...
/dev/sda1 on /boot type ext4 (rw)
/dev/sda5 on /mnt/test type ext4 (rw,usrquota,grpquota)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
//192.168.31.62/share_test on /mnt/smb_test type cifs (rw)