编程小贴士

给你的编程提供小点子


Windows与Linux文件系统互访的几种方法

首 先,我们知道基于文件的几种服务:ftp,sftp,这两种服务都是文件传输服务,偏重于网络传输,并不是实时互访。通常,我们需要在远程和本地同时操作 同一个目录,如:在Windows下使用各种强大的IDE编辑代码,在Linux下编译和运行该代码。如果在Windows下编写好代码再拷贝到 Linux下编译,这样修改时很费事,直接在Linux下修改,还要同步回Windows,相当费事。当然有人会说,所有的工作都在Linux下搞 定,VI、Linux命令行足够强大,没有需要使用Windows系统的理由,本文的重点不在讨论命令行熟练程度与工作效率的问题。

怎样像访问本地文件系统一样访问远程的文件呢?如果远程的系统与本地系统是不同类型的,又该如何做呢。

我 们知道,在Windows系统之间,可以通过共享目录的方式,让远程系统直接访问。其实这里是Windows提供一种远程文件系统机制,NAS协议的一种 ——CIFS协议。如果是Linux系统呢,同样有另外一种NAS协议——NFS协议来实现远程访问。那么这两种NAS协议能否互通呢?答案是否定的。虽 然二者不能互通,但是,在Linux系统上面已经有了CIFS协议的服务端和客户端的实现,这样,无论是Linux给Windows共享还是 Windows给Linux共享都可以借助这些已有的实现来做到了。

相反的,Windows上面有没有NFS的客户端或者服务端呢?也有,但是不常用,这里就不详细介绍了。

这里主要围绕着Linux上面使用CIFS协议来阐述如何实现两个系统之间的跨文件系统,跨操作系统共享。按照上面的描述,有两种方式来实现共享。Linux分别作为CIFS的服务端和客户端。下面分别就这两种方式来说明操作步骤和简单的原理介绍:

一、Samba软件实现共享Linux文件系统给Windows用户

Samba软件被誉为10大最有价值的开源软件之第五位。其获取方式非常容易,配置使用也非常简单。samba一般都是linux自带的,每种linux具体安装方式不一样,下面以fedora系统为例,先看一下本地是否已经安装好samba,如果/etc/init.d/smb 文件存在,则说明已经安装好了samba软件,否则使用如下命令安装:

yum install samba

安装完成后,修改配置文件,打开:/etc/samba/smb.conf,在文件末尾加上如下配置:

[root]
  comment = root
  path = / 
  create mask = 64
  writeable = yes 
  browseable = yes
  valid users = root

这个配置的意思是,创建一个名为root的共享,将根文件目录“/”共享给用户。允许登录的用户名是root。

然后给samba系统添加root用户,使用如下命令:

smbpasswd -a root

按照提示设置root用户的密码。

重新启动samba服务。

service smb restart

检查smb进程是否已经运行:

root      1787  0.0  0.4  33068  4784 ?        Ss   21:51   0:00 smbd
root      1788  0.0  0.2  33068  2580 ?        S    21:51   0:00  \_ smbd

在需要访问该Linux系统的Windows客户机上面,打开Windows的资源管理器,在地址栏输入:\\192.168.1.110

会 发现,提示有一个共享root,双击访问时,提示输入用户名和密码,输入此前配置的root用户和密码即可访问。这里就是Samba软件实现了CIFS的 服务端,Windows资源管理作为客户端访问远程的共享文件系统。为了更为方便的使用该文件系统,还可以将该共享映射成一个本地的盘符,让 Windows上面的各种工具像使用本地磁盘一样使用该目录。所有在Windows上面对该共享做的操作都会实时同步到Linux系统上面。

二、Linux访问Windows的共享

上 面的借助于Samba的方式是大家常用的。还有一种,Windows系统天然就是一个CIFS的服务端和客户端,既然Windows系统可以给 Windows系统共享目录,那么Linux系统能否访问这些共享呢?答案是肯定的,由于有强大的VFS支撑,Linux支持挂载和访问各种文件系统。 mount工具支持挂在CIFS甚至NTFS的文件系统。如果是Windows本机上面的Linux虚拟机,那么可以直接通过虚拟机管理软件,如 Vmware直接共享本地的磁盘分区给Linux系统,Linux系统根据Windows的磁盘分区的文件系统类型挂载即可。这里不详述该方案。

进入本段的正题,首先我们需要共享一个Windows的目录:

下面以Windows XP为例,Windows 7未做验证,应该类似。在共享之前,首先需要确保Windows系统的server服务处于启动状态,如下图:

tips1000_2014-11-22_03-36-22

选择需要共享的目录,右键,属性,选择“共享”页,如下图:

tips1000_2014-11-22_03-36-222

选择在网络上共享这个文件夹,并指定共享名。根据需要选择是否允许远程用户修改该文件夹。这样这个文件夹就被共享给远程访问了。

tips1000_2014-11-22_03-36-221

在Linux系统下挂载该共享:

[root@f2 ~]# mount -t cifs -o username="Test" //192.168.1.100/sourcecode /root/sourcecode
Password for Test@//192.168.1.100/sourcecode:

按照要求输入指定用户的密码即可。

此时,Windows的共享sourcecode目录就已经挂载到Linux系统上面了,Linux系统可以像访问本地目录一样访问该目录了。

这 种方法应该是更好的访问方式,因为一般而言,我们操作的文件和工作空间都是在Windows上面的,只有少数时候,需要在Linux上面进行编译,调试。 但是用起来稍显麻烦。注意,此前曾遇到过Windows系统与虚拟出来的Linux系统之间无法传输数据的问题,原因是Windows系统的防火墙未开启

70 Responses to “ Windows与Linux文件系统互访的几种方法 ”

  1. me suba说道:

    Ygfqgc Normally I do not learn article on blogs, however I wish to say that this write-up very compelled me to take a look at and do so! Your writing style has been amazed me. Thanks, quite great article.

  2. It as really a nice and useful piece of info. I am glad that you shared this helpful info with us. Please keep us informed like this. Thanks for sharing.

  3. There is certainly a great deal to find out about this topic. I like all the points you made.

  4. Oluwadamilare说道:

    Muchos Gracias for your blog post.Really thank you! Awesome.

  5. home page说道:

    Simply a smiling visitant here to share the love (:, btw great style. Treat the other man as faith gently it is all he has to believe with. by Athenus.

  6. w88world.com说道:

    What kind of camera was used? That is definitely a really good superior quality.

  7. This excellent website really has all the info I needed concerning this subject and didn at know who to ask.

  8. It?s actually a cool and useful piece of information. I?m satisfied that you just shared this helpful info with us. Please keep us up to date like this. Thanks for sharing.

  9. tui xach dep说道:

    What as up to every body, it as my first pay a visit of this web site; this website consists of amazing and genuinely good data designed for visitors.

  10. pre booked说道:

    Wow, great blog.Really thank you! Will read on

  11. status online说道:

    Im obliged for the article post.Much thanks again. Really Cool.

  12. more details说道:

    So funcy to see the article within this blog. Thank you for posting it

  13. Many thanks for publishing this, I ave been on the lookout for this details for a whilst! Your site is awesome.

  14. This excellent website definitely has all of the info I wanted about this subject and didn at know who to ask.

  15. PhD Green Card说道:

    There is clearly a bundle to know about this. I assume you made certain nice points in features also.

  16. click说道:

    Im grateful for the blog.Much thanks again. Really Great.

  17. I think this is a real great blog post.Much thanks again.

  18. klm promo code说道:

    Very nice post and right to the point. I am not sure if this is actually the best place to ask but do you folks have any ideea where to get some professional writers? Thanks

  19. Im obliged for the article post.Really looking forward to read more.

  20. This excellent website certainly has all of the information I needed concerning this subject and didn at know who to ask.

  21. some really good info , Gladiola I discovered this.

  22. Im thankful for the blog post.Really thank you! Will read on

  23. thiet ke website说道:

    I regard something really special in this web site.

  24. It as hard to find well-informed people on this subject, but you sound like you know what you are talking about! Thanks

  25. Online说道:

    Some genuinely prime articles on this web site , saved to favorites.

  26. Very interesting information!Perfect just what I was searching for! Water is the most neglected nutrient in your diet but one of the most vital. by Kelly Barton.

  27. click here说道:

    you made running a blog look easy. The overall glance

  28. womensfit说道:

    Major thankies for the post.Much thanks again. Want more.

  29. Really enjoyed this blog.Thanks Again. Cool.

  30. Thanks-a-mundo for the article post.Really looking forward to read more. Really Great.

  31. Thankyou for this wonderful post, I am glad I detected this site on yahoo.

  32. Crochet basico说道:

    Wow! This could be one particular of the most beneficial blogs We have ever arrive across on this subject. Basically Great. I am also an expert in this topic therefore I can understand your hard work.

  33. Polainas tejidas说道:

    you will have an ideal weblog right here! would you like to make some invite posts on my blog?

  34. You are my inspiration , I have few blogs and often run out from to brand.

  35. Waec expo说道:

    Say, you got a nice blog post.Really looking forward to read more. Fantastic.

  36. Im thankful for the blog.Thanks Again. Will read on

  37. loves can you say that about?) louis vuitton hlouis vuitton handbags replicabags replica it as back this fall in mouth watering chocolate. How can you go wrong

  38. Some genuinely choice blog posts on this site, saved to bookmarks.

  39. Simply desire to say your article is as surprising.

  40. What sort of camera is that? That is certainly a decent high quality.

  41. Salaam everyone. May Allah give peace, Love and Harmony in your lives for the NEW YEAR.

  42. Victor说道:

    There is obviously a bunch to identify about this. I suppose you made various good points in features also.

  43. you ave got a fantastic weblog right here! would you wish to make some invite posts on my weblog?

  44. magnificent issues altogether, you simply won a emblem new reader. What may you recommend in regards to your post that you just made a few days in the past? Any sure?

  45. very nice publish, i certainly love this website, carry on it

  46. time to look over it all at the moment but I have saved it and also added in your RSS feeds, so when

  47. go to source说道:

    Nice post. I learn something new and challenging on blogs I stumbleupon every day. It will always be exciting to read articles from other writers and practice something from other websites.

  48. Very informative blog article.Really looking forward to read more. Fantastic.

  49. Really informative blog article.Really thank you! Want more.

  50. paul smith ?? Listed Here Is A Solution That as Even Assisting bag-masters Grow

  51. Salute! Thank you very much for this marvelous website. It was fantastic joy to read.

  52. It’а†s really a great and helpful piece of info. I’а†m happy that you simply shared this helpful info with us. Please keep us informed like this. Thanks for sharing.

  53. booyoung vina说道:

    This very blog is really interesting and besides amusing. I have discovered helluva helpful things out of this blog. I ad love to visit it again and again. Thanks a bunch!

  54. miller electric说道:

    Why is there a video response of a baby with harlequin ichtyosis

  55. Very Fascinating Blog! Thank You For This Blog!

  56. go to说道:

    Major thankies for the article post. Really Cool.

  57. It as the little changes which will make the largest changes.

  58. Wonderful work! That is the kind of information that should be

  59. There as noticeably a bundle to learn about this. I assume you made sure nice points in features also.

  60. click说道:

    You need to participate in a contest for probably the greatest blogs on the web. I will recommend this site!

  61. yeezy boost 350说道:

    Thank you for all your valuable effort on this website. My niece really likes making time for internet research and it is simple to grasp why. I know all of the dynamic means you provide worthwhile items through your website and even boost participation from others on this theme so my princess is really discovering a lot. Take pleasure in the remaining portion of the new year. You’re the one doing a stunning job.

  62. daftar pb garena说道:

    Sweet blog! I found it while searching on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I ave been trying for a while but I never seem to get there! Appreciate it|

  63. go there说道:

    wow, awesome blog post.Really thank you! Awesome.

  64. Thank you for your blog article.Really thank you! Much obliged.

  65. I value the blog.Really thank you! Want more.

  66. orlando seo说道:

    one of our visitors just lately recommended the following website

  67. This is one awesome post.Really looking forward to read more. Will read on…

  68. click here说道:

    You are my breathing in, I own few web logs and occasionally run out from brand . Analyzing humor is like dissecting a frog. Few people are interested and the frog dies of it. by E. B. White.

  69. good morning说道:

    Really informative blog post.Really thank you! Want more.

  70. Perfect piece of work you have done, this website is really cool with fantastic info.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>