发布时间:2023-01-26 15:00
smb = Server Message Block windows系统共享文件时用到的协议smb
cifs = Common Internet File System Linux 系统共享文件时用到的协议cifs
实际上smb和cifs是一回事
[root@westosa100 ~]# dnf install samba samba-common samba-client -y
[root@westos_student50 Desktop]# dnf install samba samba-common samba-client -y
[root@westosa100 ~]# systemctl enable --now smb
[root@westosa100 ~]# firewall-cmd --permanent --add-service=samba
[root@westosa100 ~]# firewall-cmd --reload
[root@westosa100 ~]# mkdir /westosshare
[root@westosa100 ~]# touch /westosshare/westosfile{1..5}
[root@westosa100 ~]# semanage fcontext -a -t samba_share_t '/westosshare(/.*)?'
[root@westosa100 ~]# restorecon -RvvF /westosshare/
[root@westosa100 ~]# vim /etc/samba/smb.conf
[westos_smb]
comment = local westosdir
path = /westosshare
[root@westosa100 ~]# systemctl restart smb.service
[root@westos_student50 Desktop]# smbclient -L //172.25.254.100/westos_smb
Enter SAMBA\root's password:
Anonymous login successful
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
westos_smb Disk local westosdir
IPC$ IPC IPC Service (Samba 4.11.2)
SMB1 disabled -- no workgroup available
[root@westos_student50 Desktop]# smbclient //172.25.254.100/westos_smb
Enter SAMBA\root's password:
Anonymous login successful
tree connect failed: NT_STATUS_ACCESS_DENIED
[root@westosa100 ~]# id westos
uid=1000(westos) gid=1000(westos) groups=1000(westos)
[root@westosa100 ~]# smbpasswd -a westos
New SMB password:
Retype new SMB password:
Added user westos.
[root@westosa100 ~]# pdbedit -L
westos:1000:westos
[root@westos_student50 Desktop]# smbclient //172.25.254.100/westos_smb -U westos
Enter SAMBA\westos's password:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Sat Nov 27 14:43:31 2021
.. D 0 Sat Nov 27 14:42:50 2021
westosfile1 N 0 Sat Nov 27 14:43:31 2021
westosfile2 N 0 Sat Nov 27 14:43:31 2021
westosfile3 N 0 Sat Nov 27 14:43:31 2021
westosfile4 N 0 Sat Nov 27 14:43:31 2021
westosfile5 N 0 Sat Nov 27 14:43:31 2021
[root@westos_student50 Desktop]# mount //172.25.254.100/westos_smb /mnt/ -o username=westos,password=westos
[root@westos_student50 Desktop]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 1893192 0 1893192 0% /dev
tmpfs 1921028 0 1921028 0% /dev/shm
tmpfs 1921028 18392 1902636 1% /run
tmpfs 1921028 0 1921028 0% /sys/fs/cgroup
/dev/sda3 79127812 24645932 54481880 32% /
/dev/sda1 518816 220672 298144 43% /boot
/dev/loop0 8238560 8238560 0 100% /var/www/html/source
tmpfs 384204 16 384188 1% /run/user/42
tmpfs 384204 24 384180 1% /run/user/0
//172.25.254.100/westos_smb 17814528 3736040 14078488 21% /mnt
[root@westos_student50 Desktop]# ls /mnt
westosfile1 westosfile2 westosfile3 westosfile4 westosfile5
[root@westos_student50 Desktop]# dnf install autofs-1:5.1.4-40.el8.x86_64 -y
[root@westos_student50 Desktop]# umount /mnt ###将之前的挂载先卸掉
[root@westos_student50 Desktop]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 1893192 0 1893192 0% /dev
tmpfs 1921028 0 1921028 0% /dev/shm
tmpfs 1921028 18392 1902636 1% /run
tmpfs 1921028 0 1921028 0% /sys/fs/cgroup
/dev/sda3 79127812 23624204 55503608 30% /
/dev/sda1 518816 220672 298144 43% /boot
/dev/loop0 8238560 8238560 0 100% /var/www/html/source
tmpfs 384204 16 384188 1% /run/user/42
tmpfs 384204 24 384180 1% /run/user/0
[root@westos_student50 Desktop]# vim /etc/auto.master
/smb /etc/auto.samba ####最终挂载点的上层目录 自动挂载子策略文件
[root@westos_student50 Desktop]# vim /etc/auto.samba
westos_smb -fstype=cifs,username=westos,password=westos ://172.25.254.100/westos_smb
##最终挂载点 挂载参数 挂载资源
[root@westos_student50 Desktop]# vim /etc/autofs.conf
timeout = 3 ###默认300秒,资源闲置就会卸载,这里为了试验效果改为3s
[root@westos_student50 Desktop]# systemctl restart autofs
[root@westos_student50 Desktop]# cd /smb/westos_smb
[root@westos_student50 westos_smb]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 1893192 0 1893192 0% /dev
tmpfs 1921028 0 1921028 0% /dev/shm
tmpfs 1921028 18400 1902628 1% /run
tmpfs 1921028 0 1921028 0% /sys/fs/cgroup
/dev/sda3 79127812 23622408 55505404 30% /
/dev/sda1 518816 220672 298144 43% /boot
/dev/loop0 8238560 8238560 0 100% /var/www/html/source
tmpfs 384204 16 384188 1% /run/user/42
tmpfs 384204 24 384180 1% /run/user/0
//172.25.254.100/westos_smb 17814528 3736032 14078496 21% /smb/westos_smb
[root@westos_student50 westos_smb]# cd
[root@westos_student50 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 1893192 0 1893192 0% /dev
tmpfs 1921028 0 1921028 0% /dev/shm
tmpfs 1921028 18400 1902628 1% /run
tmpfs 1921028 0 1921028 0% /sys/fs/cgroup
/dev/sda3 79127812 23622408 55505404 30% /
/dev/sda1 518816 220672 298144 43% /boot
/dev/loop0 8238560 8238560 0 100% /var/www/html/source
tmpfs 384204 16 384188 1% /run/user/42
tmpfs 384204 24 384180 1% /run/user/0
当写到单独共享时之对此共享生效,当写到【GLOBAL】时对samba整体生效,下面是写到单独的共享目录westos_smb中的
hosts allow 172.25.254.30 白名单
hosts deny 172.25.254.50 黑名单
samba 的常用配置参数 #####
writable = yes ##可写
write list = westos ##指定用户可写
write list = +westos ##指定组成员可写
write list = @westos ##指定组成员可写
valid users = lee ##指定访问用户,只有lee可以使用共享文件
valid users = +lee|@lee ##指定访问组
browseable = yes|no ##是否隐藏共享,隐藏后看不见共享文件,但可以使用
map to guest = bad user ##写到全局设定中
guest ok = yes ##允许匿名用户访问
admin users = lee ##指定此共享的超级用户身份
[root@westos_student50 Desktop]# dnf install cifs-utils -y
[root@westos_student50 Desktop]# vim /root/smbpass
username=westos
password=westos
[root@westos_student50 Desktop]# mount -o credentials=/root/smbpass,sec=ntlmssp,multiuser //172.25.254.100/westos_smb /mnt/ #credentials=/root/smbpass 指定认证文件#sec=ntlmssp 指定认证类型#multiuser 支持多用户
[root@westos_student50 Desktop]# su - westos
Last login: Sun Nov 28 09:48:06 CST 2021 on pts/2
[westos@westos_student50 ~]$ cifscreds add -u westos 172.25.254.100
Password:
[westos@westos_student50 ~]$ ls /mnt
ls: cannot access '/mnt': Permission denied
[westos@westos_student50 ~]$ cifscreds clearall
[westos@westos_student50 ~]$ cifscreds add -u westos 172.25.254.100
Password:
[westos@westos_student50 ~]$ ls /mnt
westosfile1 westosfile2 westosfile3 westosfile4 westosfile5
用于 linux linux ,linux unix , unix unix 之间实现文件共享
[root@westosa100 ~]# dnf install nfs-utils
[root@westosa100 ~]# systemctl enable --now nfs-server
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.
[root@westosa100 ~]# firewall-cmd --permanent --add-service=rpc-bind
[root@westosa100 ~]# firewall-cmd --permanent --add-service=mountd
[root@westosa100 ~]# firewall-cmd --permanent --add-service=nfs
[root@westosa100 ~]# firewall-cmd --reload
[root@westosa100 ~]# showmount -e 172.25.254.100
Export list for 172.25.254.100:
[root@westos_student50 ~]# showmount -e 172.25.254.100
Export list for 172.25.254.100: