首页 > 系统相关 >Linux 挂载 Windows 共享文件夹 cifs

Linux 挂载 Windows 共享文件夹 cifs

时间:2024-01-01 11:02:55浏览次数:30  
标签:systemd fs cifs service Windows mount Linux 挂载


Linux 挂载 Windows 共享文件夹 cifs

一台Windows系统(192.168.1.10),创建一个共享文件夹share。

Windows客户端访问路径就是:

\\192.168.1.10\share

Linux下挂载方法如下(CentOS 7):

1).需要安装cifs-utils软件包

yum install -y cifs-utils

2).不管是开机自动挂载还是手动挂载,我们都首先在/mnt目录下创建一个文件夹,也就是挂载点。

mkdir /mnt/windows

3).手动挂载
手动挂载就是采用Linux的mount命令,终端输入如下命令:

mount.cifs //192.168.1.10/share /mnt/windows/ -o user=administrator,pass=<Windows密码>

说明:

  1. 第一个字段mount.cifs表示采用CIFS(Common Internet File System:通用网络文件系统)挂载将要挂载的目录,linux支持多种文件系统,如ext4, xfs, btrfs, f2fs, vfat, ntfs,CIFS是其中一种,具体可以看man 8 mount手册;
  2. 第二个字段表示将要挂载的文件系统路径或块设备;
  3. 第三个字段表示Linux的挂载点,也就是我们刚才创建的/mnt/windows目录;
  4. 最后一个字段-o 以及后面的所有内容表示挂载选项,各个选项以“,”分隔。比如此挂载需要知道Windows的用户名和密码;
  5. 操作可能需要root权限,可以在命令前面加sudo;

4).自动挂载
编辑fstab,增加一行

vi /etc/fstab
//192.168.1.10/share /mnt/windows/ cifs username=administrator,password=<Windows密码> 0 0

重启测试无效!!!

创建自己的systemd服务

Step1:编写属于自己的unit文件,命令为mount-fs.service,整个文件如下:

echo '
[Unit]
Description=mount-fs Service
#等待网络启动,等待远程文件系统(测试可选)
After=network.target network.service NetworkManager.service remote-fs-pre.target

[Service]
Type=oneshot
ExecStart=/bin/bash /root/mount-fs.sh
StandardOutput=syslog
StandardError=inherit

[Install]
WantedBy=multi-user.target
' > /usr/lib/systemd/system/mount-fs.service

Step2:将上述的文件拷贝到RHEL 7系统中/usr/lib/systemd/system/*目录下

Step3:编写unit文件中ExecStart=/bin/bash /root/mount-fs.sh所定义的mount-fs.sh文件,将其放在定义的目录当中,此文件是服务的执行主体。文件内容如下:

echo '
#!/bin/bash
mount.cifs //192.168.1.10/share /mnt/windows/ -o user=administrator,pass=Passwd123
' > /root/mount-fs.sh

Step4:将mount-fs.service注册到系统当中执行命令:

systemctl enable mount-fs.service

输出:

Created symlink from /etc/systemd/system/multi-user.target.wants/mount-fs.service to /usr/lib/systemd/system/mount-fs.service.

输出表明,注册的过程实际上就是将服务链接到/etc/systemd/system/目录下。

备注:取消

systemctl disable mount-fs.service
rm -f /usr/lib/systemd/system/mount-fs.service
rm -f /root/mount-fs.sh


标签:systemd,fs,cifs,service,Windows,mount,Linux,挂载
From: https://blog.51cto.com/sysin/9056561

相关文章

  • 禁用 Firefox 自动更新(Windows 版)
    禁用Firefox自动更新(Windows版)使用策略文件官方策略模板:https://github.com/mozilla/policy-templates/releases创建策略文件:<Firefox安装目录>\distribution\policies.json内容如下,{"policies":{"DisableAppUpdate.":false}}使用注册表操作步骤:浏览到“HKEY_LOC......
  • 将linux的manpages换成中文
    一种解决方法:https://blog.csdn.net/qq_23274715/article/details/104710448具体方法ubuntu:1、安装软件包sudoaptupdatesudoaptinstallmanpages-zh.使用此命令安装中文manpages库。2、查看中文包的安装路径dpkg-Lmanpages-zh使用此命令查看manpages-zh库......
  • linux 终端使用 printf 命令
     001、输出字符串[root@pc1test1]#ls[root@pc1test1]#printf"helloworld\n"##方法一helloworld[root@pc1test1]#printf"%s\n""helloworld"##方法二helloworld 002、输出整型[root@pc1test1]#ls[root@pc1test1]#pr......
  • linux 中while 循环read读入数据 使用IFS指定分割符
     001、测试数据[root@pc1test1]#lsa.txt[root@pc1test1]#cata.txt##测试数据d_jjkdd_kk 002、不指定分隔符[root@pc1test1]#lsa.txt[root@pc1test1]#cata.txt##测试数据d_jjkdd_kk[root@pc1......
  • linux 中 paste、cat 结合管道符合并方向调整
     001、paste[root@pc1test1]#lsa.txtb.txt[root@pc1test1]#cata.txt##测试文件01020304050607080910[root@pc1test1]#catb.txt##测试文件12[root@pc1test1]#cut......
  • MD-NEXT 2.0 (Windows) - 移动取证软件
    MD-NEXT2.0(Windows)-移动取证软件MobileForensicSoftware请访问原文链接:https://sysin.org/blog/md-next/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgMD-NEXT-移动取证软件适用于智能手机、功能手机、无人机、智能电视、可穿戴设备、物联网设备、USIM......
  • Cellebrite Physical Analyzer 7.65 (Windows) - 数字数据审查
    CellebritePhysicalAnalyzer7.65(Windows)-数字数据审查TheIndustryStandardforDigitalDataExamination请访问原文链接:https://sysin.org/blog/cellebrite-physical-analyzer/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgCellebritePhysicalAnalyze......
  • Cisco Jabber 14.3 (Andriod, iOS, macOS, Windows) - 面向企业的多合一通信工具
    CiscoJabber14.3(Andriod,iOS,macOS,Windows)-面向企业的多合一通信工具即时消息、语音和视频通话、语音邮件、桌面共享、会议和在线状态请访问原文链接:https://sysin.org/blog/cisco-jabber-14/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org思科Jabber......
  • Linux内核socket系统调用源码分析
    一、环境说明内核版本:Linux3.10内核源码地址:https://elixir.bootlin.com/linux/v3.10/source(包含各个版本内核源码,且网页可全局搜索函数)二、应用层-socket()函数应用层创建socket对象返回整型的文件描述符。/*family:被称为协议族,或者协议域。*type:套接字类型。*......
  • Windows Terminal的资料
    WindowsTerminal是微软Windows平台难得好用的工具。由于工作内容的原因,需要打开多个CMD窗口、多个gitbash窗口,并且在多个窗口间切换,因此命令行窗口支持多TAB的特性,变成了一个刚需,而这正是WindowsTerminal的卖点。在网上查找资料时无意中看到工具的介绍,于是毫不犹豫的下载、安......