This tutorial will help you setup older versions of Ubuntu to access files on Windows home computers. It covers the steps needed for both operating systems.

NOTE - To learn how to setup file-sharing on Ubuntu please refer to the guide, http://help.ubuntu.com/community/SettingUpSamba

This guide is compatible with the following versions of Ubuntu:

It should also work on these versions of Microsoft Windows (with a Workgroup configuration, not Domain).

It has however only been tested on "Feisty Fawn" and "Windows XP 64-bit Edition" so far.

In this guide we will set up a share on Windows and access it from Linux. This appears to be the most reliable and natural configuration.

Info (!) Samba is Linux's implementation of Windows' SMB (Server Message Block) protocol.

Configuring SMB on Windows

Installing the SMB Protocol

On your Windows machine, right-click on the My Network Places icon, then select Properties. If you do not have a network icon you can instead open a command prompt by going to the start menu and pressing run. Type cmd and click OK. In the command prompt, type this command (the > prefix should be ignored):

> control netconnections 

In the list of network properties, right-click on the icon of your primary network adapter and select Properties. Ensure File and Printer Sharing... is listed. If it is not you can use the Install button to install that service.

Info <!> If you have the XP firewall enabled, ensure that File and Printer Sharing is selected under the Exceptions tab for the firewall configuration. Likewise, make sure any other firewall you are using does not restrict SMB (sharing) access.

Configuring Workgroup and Computer Name

Right click on My Computer on the desktop and go to Properties. Choose the Computer Name tab at the top. Click Change... and use Workgroup. In this example we will use MSHOME for the workgroup name as that is also the default in Ubuntu's Samba. Also enter a computer name (in this example, DEVMACHINE). Workgroup and computer names are not case-sensitive. It is important to reboot now if it wants you to. Please reboot, don't simply log out.

Setting Up Access Control

We will need to add a group and user to effectively control access to our Windows shares.

Go back to your command line, and type these lines. Change ShareAccessPassword to a password of your choice.

> net localgroup UbuntuSMB /add
> net user ubuntu ShareAccessPassword /add /passwordchg:no /expires:never
> net localgroup UbuntuSMB ubuntu /add
> net localgroup Users ubuntu /delete 

We're also going to have to make sure the password never expires. Type:

> compmgmt.msc 

Find the Local Users and Groups section under System Tools. Right click on the ubuntu user and select Properties. Enable Password Never Expires and click OK.

Disable Simple Sharing

This feature does not make sharing any easier; it's basically a roadblock. Open the Control Panel double click Folder Options, Click the View tab and disable Use simple file sharing. Click OK to exit the dialog.

Setting Up Your Shares

In Explorer, find a drive or folder that you would like to share. In my example I will be sharing a folder at c:\shares. Right click the folder or drive and select Properties. Go to the Sharing tab and enable Share this folder. Enter a proper share name (shares in this example). Click Permissions and remove the Everyone group from the list. Now add the UbuntuSMB group (Add... and type in UbuntuSMB and click OK). Set the desired permissions for how Ubuntu should be able to access this share (in my example, I enabled full read/write access). This should mean that nobody is allowed to access the share, except for users in the UbuntuSMB group. If you explicitly press Deny on Everyone, that would also Deny UbuntuSMB since Deny has precedence over Allow and we don't want that.

Info <!> If you connect to the share by using a user that is not in the UbuntuSMB group, the connection will succeed but the mount point will not at all be accessible, even by root. The listing will appear as such:

?---------  ? ?    ?          ?                ? winshares 

Info (!) You can change the Access Control List (ACL), the permissions, while the share is mounted without having to restart any service on either operating system. The changes will immediately take effect. [As of: Feisty Fawn; Windows XP 64-bit Edition]

Configuring Samba on Ubuntu

Installing Samba

Open a terminal by going to Applications->Accessories->Terminal and type the following.

$ sudo apt-get install samba smbfs
$ sudo mkdir -p /media/winshares
$ sudo addgroup smb
$ sudo adduser $USER smb 

You must now log out to ensure your user is now in the smb group. You do not have to reboot.

Is it true that smbfs is deprecated? According to a blog post by Joey Stanford we need to use CIFS instead of smbfs!

Testing Your Shares

Now let's try and mount our Windows share! Remember to replace ShareAccessPassword with the ubuntu user's password. The user name for the login is not case-sensitive, although the password is. Also, use the proper workgroup and share names. "//DEVMACHINE/shares" is called our share path. This is a type of UNC path where the format is //COMPUTER_NAME/SHARE_NAME. In Windows, backslashes are used instead of forward slashes to access UNC paths. Recall that we used "DEVMACHINE" for our computer name and "shares" for our share name.

$ sudo mount -t cifs -o username=ubuntu,password=ShareAccessPassword,workgroup=MSHOME,gid=smb,uid=$USER,file_mode=770,dir_mode=770,rw //DEVMACHINE/shares /media/winshares 

Info <!> By using the 770 permission, we are giving full access to the owner (the current user), to everybody in the smb group, and no access at all to users not in the smb group.

Info <!> If your share name contains a space, you must enclose the share name in double quotes, e.g. for a share named "Share with Spaces":

To test another share you must specify another share path (e.g. //DEVMACHINE/shares) and target (e.g. /media/winshares).

Break Down

If your terminal printed nothing, it probably mounted just fine. Verify that the permissions are what you expect.

$ stat -c %a /media/winshares 

If they are different than 770 as specified, verify that you typed the mount command properly.

Info <!> Vital Note: you can not mount a whole computer to one location. For example, you can not mount the whole //DEVMACHINE/ computer to one folder on your Linux system. You also need to be careful about how you specify your share path. //DEVMACHINE/shares will work, but //DEVMACHINE/shares/ will return the following!

25034: tree connect failed: ERRDOS - ERRnosuchshare (You specified an invalid share name)
SMB connection failed 

Automatically Mounting the Shares

Securing Our Password

Registering Our Shares

Testing fstab

Congratulations

Your shares should be working perfectly now, secure and reliable. The shares should appear in your filesystem at boot-up automatically.

Troubleshooting

For now this section is empty. Please add any errors and solutions to them that you may find.

This document seems to do a good job documenting how to access files on a Windows machine from a Ubuntu machine. So ... How do I read and write files on a Ubuntu fileserver from a Windows machine? Does some other wiki.ubuntu page that describes that? Please link to it here. -- Davidcary 2007-04-30 23:24:30

ComprehensiveSambaGuide (last edited 2009-02-11 15:23:48 by adsl-75-3-207-217)