惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

server – Ed_'s Blog

给 Debian 开了自动安全更新 – yywr's Blog Crontab 使用笔记 – yywr's Blog 终于修了个梯子 – yywr's Blog 防火墙配置工具 UFW – yywr's Blog 说说 LNMP 面板 – yywr's Blog Linux 程序开机启动并保活:Systemd 进程守护管理工具 – yywr's Blog Ubuntu 开机自动挂载第二块硬盘 – yywr's Blog 重装了家里的服务器系统 – yywr's Blog 构建网络私有书架,实现听书看书 – yywr's Blog 主机安装 Tiny Tiny RSS 踩坑记 – yywr's Blog
Linux 下自动挂载 Samba /CIFS 共享文件夹 – yywr's Blog
yywr · 2023-02-11 · via server – Ed_'s Blog

之前说到Linux下开机自动挂载第二块硬盘,那就不得不提一下之前在Mint下碰到的一个需求,挂载SMB(Server Message Bloc)文件夹,也就是Windows下默认的文件夹共享协议。

当时我使用 Mint 系统 ,想要访问一个地址 // 开头的共享文件夹,使用图形界面和 Mount 都很容易的挂载上了,但我想通过 /etc/fstab 文件让系统开机挂载这个文件夹时却碰上了问题,找了很多资料都没解决。不是不能挂载,也不是不能访问,而是访问之后没有编辑权限。最后找一个生效的配置方法,这也促使我找资料尽量原始资料,哪怕需要通过翻译软件查看,哪怕需要自己琢磨

解决方法

找个地方创建一个文件,用来保存访问SMB文件夹需要的账户信息,比如 ~/.smbCred 

 #创建文件
nano ~/.smbCred
#在里面写入账户和密码,域可以留空
user=SMBUser
password=SMBPassword
domain=

然后编辑 /etc/fstab 文件,和之前挂载硬盘时一样,新加一行,写入6个信息块,保存即可

# for Windows Server 2008 samba shares:
//yywr.net/folder	/mnt/fromsmb	cifs	uid=0,credentials=/home/yywr/.smbCred,iocharset=utf8,noperm 0 0

# for Windows Server 2016 samba shares:
//yywr.net/folder	/mnt/fromsmb	cifs	uid=0,credentials=/home/yywr/.smbCred,iocharset=utf8,vers=3.0,noperm 0 0

# 其实我的 SMB 文件夹是在 Linux 下用 samba 建立的,当时给 Windows 机器用的,我的如下:
//yywr.net/folder	/mnt/fromsmb	cifs	uid=0,credentials=/home/yywr/.smbCred,iocharset=utf8,noperm 0 0

更新:上述配置在Mint下有效,在Ubuntu 系下应该 也是有效的,在是OpenSUSE应该行不通,会报mount error(22): Invalid argument ,得用这个://192.168.1.2/folder /mnt/smbfolder cifs gid=users,file_mode=0664,dir_mode=0775,auto,username=www,password=pwd 0 0 ,参考 https://www.suse.com/support/kb/doc/?id=000016706 。这些参数让人头痛

关于参数

6个信息块之前在挂载硬盘时都说过了,这里主要说一下<type>和<options> 

type : smb共享文件夹的类型是 cifs ,微软说这是SMB协议的方言,不深究,啃这里    >>>  https://learn.microsoft.com/zh-cn/windows/win32/fileio/microsoft-smb-protocol-and-cifs-protocol-overview

options: 和之前的挂载硬盘不同,不使用defaults,cifs有自己的参数,只说一下用到的这几个,更丰富营养啃这里>>> https://linux.die.net/man/8/mount.cifs

uid: 涉及服务器端共享文件的用户权限问题,默认 0 ,不研究,因为需要更多的知识,而且家用,目前够用

credentials: 认证信息,也可以用user 和 password 直接指定, 当然,如果压根没有密码,也可以直接使用 guest 参数

iocharset: 设置 Unicode  ,防止乱码

noperm: 这是最重要的,也是解决我无写入权限的关键,这其实和第一项uid的设置有关,我没折腾好,只能通过这个参数来忽略权限检查,使用这个参数后,从客户端访问smb文件夹不再检查权限,这也就解决了我的问题

关于权限问题,还有 file_mode 、dir_mode 等参数,配置  uid  、gid 参数使用,但这好像应用在不支持 CIFS  Unix 扩展的情况,也许这也是我一开始折腾没成功的原因吧。

我的解决来源:

https://timlehr.com/auto-mount-samba-cifs-shares-via-fstab-on-linux/

本文是 居家服务器折腾笔记 的一部分