前言
linux上访问Samba共享有多种方式,现就对这些方法进行一些汇总总结。
一、用文件管理器直接访问
最简便的方法,以KDE自带的Dolphin为例,直接地址栏输入smb://,然后找到自己的samba共享,再输入用户密码即可,为了方便还可以添加到左侧的快捷栏里。
当然缺陷也非常的严重,例如播放视频时很多软件会把整个视频文件都复制到临时目录然后再进行播放,部分软件甚至会发生完全找不到文件的情况,总而言之,这着实算不上一个稳定、便捷的方案。
二、命令行手动挂载
想要避免上述问题,最简单直接的解决方案是直接把Samba共享挂载到一个目录,而最直接的方法可以通过一行命令实现:
sudo mount-t cifs //192.168.1.1/smbshare /path/smbshare -o username=username,password=passwd
或者把用户密码存到一个文件里 (记得改权限),例如 /file/file.txt(注意文件权限)
username=username
password=passwd
然后使用
sudo mount-t cifs //192.168.1.1/smbshare /path/smbshare -o credentials=/file/file.txt
这样比较繁琐,每次都要用到sudo命令,手动挂载,偶尔连接一下还行,长期使用稍显麻烦。
三、通过修改fstab挂载
另一种方法是通过修改 fstab 来挂载,编辑 /etc/fstab 并添加:
//192.168.1.1/smbshare /home/xxx/smbshare cifs user,noauto,nofail,credentials=/foo/credentials.txt 0 0
注意其中的三个选项 user, noauto 以及 nofail。
user 代表了任意用户均可使这条挂载生效,避免了每次 mount 前都要加 sudo 的情况。
noauto 代表了不会开机时自动挂载,也就是说需要开机后通过 mount -a 手动挂载。
nofail 则代表了开机时挂载失败时系统不会进入紧急维护模式,当然如果已经设置了 noauto,是否使用 nofail 就无所谓了。
修改完 fstab 后可以通过 mount -a 重新挂载或者直接重启。
这个方案也有个不足的地方,如果设置成开机自动挂载,会严重拖累系统启动速度,因为在进入登录界面之前需先要等待网络连接才行,但如果设置成 noauto 那么这种挂载方式又会变得很不方便。
实际上这种方案比较有效的用法是只开启 nofail 选项,然后用来挂载一些非常重要的目录。
四、总结
暂时记录这三种挂载方式,在这三种方式的基础上可以进行扩展,比如把手动挂载命令写进systemd服务进行开机启动等等等等,留待以后有时间再尝试。
文章评论
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Very nice post. I simply stumbled upon your blog and wanted to say that I've truly enjoyed browsing your blog posts. After all I will be subscribing on your rss feed and I am hoping you write once more very soon!
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Your article helped me a lot, is there any more related content? Thanks!
Your article helped me a lot, is there any more related content? Thanks!
Your article helped me a lot, is there any more related content? Thanks!
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Your article helped me a lot, is there any more related content? Thanks!
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your article helped me a lot, is there any more related content? Thanks!
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Your article helped me a lot, is there any more related content? Thanks!
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://www.binance.com/id/register?ref=GJY4VW8W
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://accounts.binance.com/fr-AF/register?ref=JHQQKNKN
Your article helped me a lot, is there any more related content? Thanks!
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your article helped me a lot, is there any more related content? Thanks!
Your article helped me a lot, is there any more related content? Thanks!
kxgkjzmyskijrivzwgonshpeqtnpkh
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your article helped me a lot, is there any more related content? Thanks!
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Your article helped me a lot, is there any more related content? Thanks!
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
oskeelekkfyuteswfljgkgzumxiild
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
ikuvsjnippoqlufrulezyiltqnqwmr
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thank you, your article surprised me, there is such an excellent point of view. Thank you for sharing, I learned a lot.