设为首页 加入收藏

TOP

Linux SAMBA 服务-cifs文件系统的挂载
2023-07-23 13:38:50 】 浏览:20
Tags:Linux SAMBA 服务 -cifs 文件系

相关概念

SMB:

??Server Message Block 服务器消息块,属于微软的私有协议,是windws之间相互共享资源的一种协议。

cifs:

??common internet file system,基于smb开发而来的文件系统,通过internet共享文件系统。

#linux也支持cifs这种文件系统

[root@LAP1 fs]# ls
binfmt_misc.ko.xz  ceph  cramfs  ext4  fscache  gfs2   jbd2   mbcache.ko.xz  nfs_common  nls        pstore    udf
cachefiles         cifs  dlm     fat   fuse     isofs  lockd  nfs            nfsd        overlayfs  squashfs  xfs

[root@LAP1 fs]# pwd
/lib/modules/4.18.0-240.el8.x86_64/kernel/fs

SAMBA:

??为了让实现 Windows和UNIX相通,开发了一个软件叫做samba软件

SAMBA作用:

??在linux中安装samba软件来模拟一个windows的共享,实现windows和类unix之间的文件共享。

samba的客户端工具:samba-client

#安装客户端工具

[root@LAP1 ~]# yum install samba-client -y

范例:使用smbclient 访问SAMBA服务器

#首先使用windows开启一个叫做share的共享

#使用客户端工具列出windows列出的共享目录

#格式:smbclient -L instructor.example.com -U smb用户%password
#如果不指定用户名,默认使用的就是当前linux的用户名
#用户名和密码是windows上的用户名和密码

[root@LAP1 share]# smbclient -L 192.168.13.218/share -U admin%123456

	Sharename       Type      Comment
	---------       ----      -------
	ADMIN$          Disk      远程管理
	C$              Disk      默认共享
	D$              Disk      默认共享
	E               Disk      
	E$              Disk      默认共享
	IPC$            IPC       远程 IPC
	share           Disk      
	Users           Disk      
SMB1 disabled -- no workgroup available

例如:使用samba客户端smbclient进入指定的共享目录

#进入指定的目录

UNC路径: Universal Naming Convention,通用命名规范,格式如下
 \\sambaserver\sharename

[root@LAP1 share]# smbclient //192.168.13.218/share -U admin%123456
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Mon Oct 24 14:39:19 2022
  ..                                  D        0  Mon Oct 24 14:39:19 2022
  anaconda-ks.cfg                     A     1526  Mon Oct 24 14:31:13 2022
  file1.txt                           A       12  Mon Oct 24 14:39:19 2022
  hello.txt                           A        0  Mon Oct 24 14:26:56 2022
  iMenu@3001_40793@2.1.exe            A  3293584  Tue Oct 18 20:01:59 2022
  PAInstall                           D        0  Mon Oct 24 14:24:21 2022
  PAInstall.zip                       A 17681894  Thu Oct 13 09:22:05 2022

		139332095 blocks of size 4096. 134844217 blocks available
smb: \>

windows开启文件共享的方法:

linux挂载windows共享的目录:

  1. 安装cifs-utils工具

  2. 使用对应的格式挂载目录

挂载CIFS文件系统
mount -o user=wang,password=magedu //server//shared   /mnt/smb

例如:windows共享目录的挂载

安装cifs工具包
yum install cifs-utils -y 


[root@LAP1 ~]# vim /etc/fstab
//192.168.13.218/share  /mnt/share cifs username=admin,password=123456 0 0

# //host/dir  mount_point  文件类型为cifs  需要指定用户名何密码 0 0


[root@LAP1 ~]# mount -a
[root@LAP1 ~]# df -h
Filesystem              Size  Used Avail Use% Mounted on
devtmpfs                957M     0  957M   0% /dev
tmpfs                   975M     0  975M   0% /dev/shm
tmpfs                   975M  8.8M  966M   1% /run
tmpfs                   975M     0  975M   0% /sys/fs/cgroup
/dev/sda3                49G  2.9G   44G   7% /
/dev/sr0                8.7G  8.7G     0 100% /mnt/misc
/dev/sda1               976M  142M  768M  16% /boot
tmpfs                   195M     0  195M   0% /run/user/0
//192.168.13.218/share  532G   18G  515G   4% /mnt/share
开机自动挂载
不暴露密码
cat /etc/fstab 
#可以用文件代替用户名和密码的输入
//server/homes /mnt cifs credentials或cred=/etc/smb.txt 0 0

cat /etc/smb.txt
username=wang #或 user=wang
password=password #或 pass=password
chmod 600 /etc/smb.txt

#此方法也需要安装cifs-utils包
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇ansible的常用模块 下一篇Linux sersync + rsync 实现实时..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目