Sharing files between Windows and Linux: Samba

Status
Not open for further replies.

Phantasm66

Posts: 4,909   +8
Sharing files between Windows and Linux: Samba

Question: How do I access shared files and folders from Windows computers, and how do I share files and folders on Linux?
Answer: Samba

Explanation:

All versions of Windows, and even MS-DOS, use the SMB protocol to share files and printers, and also to handle authentication. Samba implements almost all of SMB's functionality on *NIX systems, allowing them to take the role of a Windows NT domain controller. But most of us just use it to access Windows shares on Linux. This FAQ will tell you how to do just that.

This FAQ assumes you have Samba installed and properly configured, and that your kernel supports smbfs. If you're running a distro made in the last 2 years, it's safe to assume you're all set.

To access shared folders in Linux:

Open a shell.


Become root. su and enter your root password when asked for it.


Create a mount point for the shared folder. mkdir /mnt/share


Mount the shared folder. mount -t smbfs -o username=username,password=password //compname/sharename /mnt/share

Replace username with your username on the other box and password with the associated password. Replace compname with the name of the computer, and sharename with the name of the share.
If you didn't get any errors, you're all set. The folder is "mapped" to /mnt/share.

If you DID get an error, this part might help:

If the error said "can't open /etc/smb.conf: no such file" or something like that, ignore it. You don't need a config file just to mount shares.

If the error said "wrong fs type or bad superblock n //compname/sharename", it means samba isn't installed. Install it and try again.

If it said "unknown filesystem smbfs" or "kernel doesn't support smbfs" or something like that, it means you don't have smbfs support in your kernel. Run modprobe smbfs and try again. If it still doesn't work, you will have to build a new kernel with SMB support enabled.

If it says "couldn't connect to compname", open your /etc/hosts file and add an entry for the computer you're trying to connect to.

I think I've covered everything that could possibly go wrong with mounting, so let's move on to sharing.

To share directories on Linux:

Open a shell and become root, as described before.


Open your /etc/smb.conf file. kedit /etc/smb.conf (replace kedit with your favorite editor if you want)


Alter it like so:


Change the WORKGROUP setting to the name of the workgroup you want to be in.


The HOSTS ALLOW line should contain the list of IP ranges that are on your home network. For example, if your computers were all 192.168.0.* your line would look like this:
hosts allow = 192.168.0. 127.


Set ENCRYPT PASSWORDS to "yes"


Set SMB PASSWORD FILE to "/etc/smbpasswd"


On the INTERFACES line, list all of your computer's IP addresses, except the internet address if it has one. For example, if you computer had a loopback IP 127.0.0.1, an internal IP 192.168.0.1, and an internet IP 25.246.105.108, your line would be:
interfaces = 192.168.0.1 127.0.0.1


Save it and exit the editor.


Add an account for your Windows box. smbpasswd -a user password
Replace user with the username you want. and password with a password. The username should be a valid user on the Linux box.


Open up /etc/smb.conf again.


Scroll down to the Share Definitions part.


The first chunk would be the homes section. Edit it as necessary to make it match this:
[homes]
comment = Home Directories
browseable = no
writable = yes


Now add any other shares you want like this:
[sharename]
comment = Comment
path = /path/to/share
read only = no
public = yes


Save and exit.


Now start the Samba server. nmbd -D and then smbd -D
While it's not very elaborate, or even very secure, what you have created is suitable for the home MP3 server. The hosts allow and interfaces lines are there to make the server inaccessible to anything other than the computers on your LAN, which is a pretty good security measure if you ask me.

source: http://www.anandtech.com/guides/viewfaq.html?i=125
 
Cautions about connecting to a Windows workgroup

I recently installed UBUNTU 7.04 and tried to access files on my windows computers on the same network after I had installed Samba.

I could see not even the host computer. I could see the Windows Workgroup with the correct name. When I clicked on that icon I got an error message something like "I can't access the folders".

I looked all over to discover what was wrong, but nothing I found appeared to address my problem. Clearly, my windows machines could see each other as shared files. I finally decided to rename my workgroup. I had heard that Linux used to have trouble working correctly when names had spaces in them. My workgroup name was something like "jack and jill". I changed the workgroup name on all my computers on the network to "jackandjill".

I, of course, changed the DOMAIN name on my Linux machine to JACKANDJILL and viola...it worked as it should have. I could see all my machines and all my shared files.

I suppose that most Workgroup Names don't have spaces in them, but it is something that SAMBA or one of its configuration tools should recognize as an error when a domain name is entered containing spaces.
 
Status
Not open for further replies.
Back