在之前的教程中,我展示了如何在Ubuntu中启用(Ubuntu)共享服务(sharing service)并更改工作组(Workgroup),使其与网络中的所有其他计算机相同,从而使Ubuntu 和 Windows(Ubuntu and Windows) 7 之间的网络变得更加容易。在本教程中,我将展示如何在Ubuntu中共享文件夹以及如何从Windows 7计算机访问它们。
注意:(NOTE:)文章已更新以适用于Ubuntu v10.10和 11.04。
启用文件共享和配置(File Sharing & Configure)工作组(Workgroup)
为了让Ubuntu 和 Windows(Ubuntu and Windows) 7 共享文件,必须将它们配置为同一个Workgroup的一部分。此外,需要在Ubuntu中启用文件共享。
要更改您的Windows 7工作组,请参阅:如何更改Windows 7和Windows 8中的工作组(Workgroup)。
要配置Ubuntu,请参阅:如何在Ubuntu Linux中启用(Ubuntu Linux)文件共享和更改(File Sharing & Change)工作组(Workgroup)。
正确设置这些项目后,继续本教程。
如何在 Ubuntu 中共享文件夹
首先,在 Ubuntu 中打开“位置(Places)”菜单中的主文件夹。(Home Folder)
浏览(Browse)到要共享的文件夹。右键单击它以打开上下文菜单,然后单击(menu and click)共享选项(Sharing Options)。
文件夹共享(Folder Sharing)窗口将打开。选中“共享此文件夹”('Share this folder')旁边的框。然后,在共享名称(Share name)字段中,输入您要使用的共享名称。(share name)在“评论”(Comment) 字段中输入(field type anything)您想要的任何内容或将其留空 - 无需填写。如果您想允许其他人在您共享的文件夹中创建和删除文件,请选中“允许其他人在此文件夹中创建和删除文件”('Allow others to create and delete files in this folder')旁边的复选框。此外,如果您想允许访客访问,请选中(Guest access)“访客访问(对于没有用户帐户的人)”('Guest access (for people without a user account)')旁边的框。完成后,单击创建共享(Create Share)以实际共享文件夹。
如果您选择了“允许其他人在此文件夹中创建和删除文件”('Allow others to create and delete files in this folder')选项,则会出现一个弹出窗口,询问您是否要向您正在共享的文件夹添加一些权限。单击(Click)“自动添加权限”('Add the permissions automatically')按钮。现在,该文件夹与网络的其余部分共享。
注意:(Note:)我们建议您仅共享在主文件夹中找到或创建的文件夹(Home Folder),因为这些文件夹是您的用户名拥有所有权的文件夹。如果您尝试在主文件夹之外共享文件夹(Home Folder),您将收到以下错误消息(error message):“net usershare 返回错误 255:net usershare add:无法共享路径,因为我们仅限于共享我们拥有的目录。” ("net usershare returned error 255: net usershare add: cannot share path as we are restricted to only sharing directories we own.")出现此错误是因为您没有这些文件夹的所有权。为了共享它们中的任何一个,您必须经历一个复杂的过程,这可能会给您的Ubuntu 计算机(Ubuntu computer)增加安全风险。
(Access Ubuntu Shared Folders)从Windows 7访问 Ubuntu 共享文件夹
在Ubuntu中共享文件夹后,让我们看看如何从Windows 7计算机访问该文件夹。
打开Windows 资源管理器(Windows Explorer)。单击网络(Network)可查看网络中所有可用计算机(当时已打开)的列表。
双击(Double)您要访问的Ubuntu 计算机。(Ubuntu computer)将打开包含该计算机中所有共享文件夹和设备的列表。
双击(Double)要访问的文件夹。如果您尚未将共享文件夹设置为允许访客访问(Guest access),则系统会要求您输入用户名和密码(username and password)。
在第一个输入字段中(input field),键入Ubuntu 计算机(Ubuntu computer)的名称,后跟反斜杠 ("") 以及有权访问共享文件夹的用户帐户的名称。(user account)在第二个输入字段(input field)中输入密码。如果您希望 Windows 记住您的用户名和密码,请选中(username and password)“记住我的凭据”('Remember my credentials')旁边的框。完成后,单击确定。
现在显示共享文件夹的内容。
结论
在包含Windows 7和Ubuntu计算机的网络上,您可以将Ubuntu配置为共享文件和文件夹,这些文件和文件夹可从(Ubuntu)Windows PC轻松访问。如果您想了解有关在本地网络上设置其他 PC 的更多信息,或者如何进一步利用Ubuntu Linux 和 Windows(Ubuntu Linux and Windows) 7 之间的网络功能,请查看下面列出的文章。
How to Share Folders in Ubuntu & Access them from Windows 7
In a рrevious tutoriаl I have shown how to enable the sharing service in Ubuntu and changе the Workgroup so that it іs the same with all the other computers in your network, thus mаking networking between Ubuntu and Windows 7 easіer. In this tutorial I will show how to share folders in Ubuntυ and how tо аccess them from Windows 7 computеrs.
NOTE: Article updated to work on Ubuntu v10.10 & 11.04.
Enable File Sharing & Configure the Workgroup
In order for Ubuntu and Windows 7 to share files, they have to be configured to be part of the same Workgroup. Also, file sharing needs to be enabled in Ubuntu.
To change your Windows 7 workgroup, see: How to Change the Workgroup in Windows 7 & Windows 8.
To configure Ubuntu, see: How to Enable File Sharing & Change the Workgroup in Ubuntu Linux.
Once these items are set up correctly, proceed with this tutorial.
How to Share Folders in Ubuntu
First, open the Home Folder in Ubuntu, found in the Places menu.
Browse to the folder you want to share. Right-click on it to open the contextual menu and click on Sharing Options.
The Folder Sharing window will open. Check the box next to 'Share this folder'. Then, in the Share name field, type the share name you want to use. In the Comment field type anything you want or just leave it empty - there's no need to complete it. If you want to allow others to create and delete files in the folder you are sharing, check the box next to 'Allow others to create and delete files in this folder'. Also, if you want to allow Guest access, check the box next to 'Guest access (for people without a user account)'. When done, click on Create Share to actually share the folder.
If you have selected the option 'Allow others to create and delete files in this folder' a pop-up shows up, asking if you want to add some permissions to the folder you are sharing. Click on the 'Add the permissions automatically' button. Now, the folder is shared with the rest of the network.
Note: We recommend that you only share folders found or created in the Home Folder because those are folders on which your username has ownership. If you try to share a folder outside the Home Folder, you will receive the following error message: "net usershare returned error 255: net usershare add: cannot share path as we are restricted to only sharing directories we own." This error appears because you don't have ownership on those folders. In order to share any of them you have to go through a complicated procedure that has the potential to add security risks to your Ubuntu computer.
Access Ubuntu Shared Folders from Windows 7
After you shared a folder in Ubuntu, let's see how to access that folder from a Windows 7 computer.
Open Windows Explorer. Click on Network to view a list with all computers available (turned on at that time) in the network.
Double click the Ubuntu computer you want to access. A list with all the shared folders and devices from that computer opens.
Double click the folder that you want to access. If you haven't setup the shared folder to allow Guest access, you are asked to introduce a username and password.
In the first input field, type the name of the Ubuntu computer followed by a backslash ("") and the name of the user account with access to the shared folder. In the second input field type the password. If you want Windows to remember your username and password, check the box next to 'Remember my credentials'. When done, click on OK.
Now the content of the shared folder is shown.
Conclusion
On a network with Windows 7 and Ubuntu computers, you can configure Ubuntu to share files and folders which are easily accessible from a Windows PC. If you want to know more about setting up other PCs on a local network, or how to further utilize the networking features between Ubuntu Linux and Windows 7, check out the articles listed below.