Difference between revisions of "Samba"

From Noah.org
Jump to navigationJump to search
m
Line 1: Line 1:
 
[[Category:Engineering]]
 
[[Category:Engineering]]
 
== Mount a Windows share on Linux ==
 
== Mount a Windows share on Linux ==
It's pretty easy to mount a Windows network share on Linux.
 
The mount command supports filesystem type cifs (and smbfs).
 
Assuming you want to mount the folder \\server\SharedDocs.
 
You may need to resolve your Windows \\server name to an IP address.
 
Assuming that \\server resolves to 192.168.2.4. I find it easier than
 
trying to use the Windows group names.
 
  
=== Using cifs ===
+
It's pretty easy to mount a Windows network share on Linux. The `mount` command supports filesystem type cifs (and smbfs).
 +
 
 +
You may need to resolve your Windows \\server name to an IP address. I find this easier than trying to deal with the Windows names. The following examples show how to mount a Windows folder share named '''\\server\SharedDocs''', and pretends that '''\\server''' resolves to '''192.168.2.14'''.
 +
 
 +
This shows a mount using '''cifs''':
 
<pre>
 
<pre>
 
mkdir shareddocs
 
mkdir shareddocs
Line 14: Line 12:
 
</pre>
 
</pre>
  
=== Old style using smbfs ===
+
This shows a mount using old style '''smbfs''':
 
<pre>
 
<pre>
 
mkdir shareddocs
 
mkdir shareddocs
Line 20: Line 18:
 
</pre>
 
</pre>
  
== Make SMB mounts persistent with fstab ==
+
== Make SMB mounts persistent by using fstab ==
  
Add the following to /etc/fstab and /media/SharedDocs will be automatically mounted when you reboot or run "mount -a". The IP address, 192.168.2.4, may be replaced with the Windows server name. You may also need to set username and password.
+
Add the following to '''/etc/fstab''' and '''/media/SharedDocs''' will be automatically mounted when you reboot or run `mount -a`. The IP address, 192.168.2.14, may be replaced with the Windows server name. You may also need to set username and password.
  
 
=== Using cifs ===
 
=== Using cifs ===
Line 30: Line 28:
 
</pre>
 
</pre>
  
Mount with a given group of <code>admin</code> and forced file and dir permissions.
+
This shows a mount with a given group of <code>admin</code> and forced permissions for files and directories.
  
 
<pre>
 
<pre>
Line 43: Line 41:
  
 
== Browse with smbclient ==
 
== Browse with smbclient ==
Don't put a trailing slash on the share name!
+
 
 +
Note: don't put a trailing slash on the share name!
 +
 
 
<pre>
 
<pre>
 
smbclient -UGuest //192.168.1.1/SharedDocs
 
smbclient -UGuest //192.168.1.1/SharedDocs
Line 50: Line 50:
 
== Browsing Windows workgroups in Nautilus fails with a timeout ==
 
== Browsing Windows workgroups in Nautilus fails with a timeout ==
  
The root cause of this error is probably due to your DNS. You may have it set to OpenDNS or to some other smart DNS server where it will try to guess what you meant and serve you a search page instead of just failing the way it is supposed to.
+
The root cause of this error is probably due to your DNS. You may have it set to OpenDNS or to some other "smart" DNS server that tries to guess what you meant or serves you a search page instead of just failing the way DNS is supposed to.
  
 
Samba tries to search for Windows shares through a few different methods. It first looks up names in DNS. If that fails then it tries localnet broadcasts to see if any machines answer. But if you have a "smart" DNS, then the lookup will not actually fail, so Samba will never fall-back to using broadcast lookups. Instead you will just get a timeout.
 
Samba tries to search for Windows shares through a few different methods. It first looks up names in DNS. If that fails then it tries localnet broadcasts to see if any machines answer. But if you have a "smart" DNS, then the lookup will not actually fail, so Samba will never fall-back to using broadcast lookups. Instead you will just get a timeout.
  
If you can't fix your DNS then you can change the name resolution order that Samba uses. Edit the file, '''/etc/samba/smb.conf''' and find the line like this:
+
If you can't fix your DNS then you can change the name resolution order that Samba uses. Edit the file, '''/etc/samba/smb.conf''' and find the '''name resolve order''' line similar to this:
  
 
<pre>
 
<pre>
Line 60: Line 60:
 
</pre>
 
</pre>
  
It may be slightly different. The important thing is to find 'name resolve order'. Change this line so that it is uncommented and the resolution order is different:
+
Your values may be slightly different. Change this line so that it is uncommented and the resolve order puts '''host''' at the end of the list:
  
 
<pre>
 
<pre>
Line 74: Line 74:
 
Sometimes the first time I browse the Windows network I will get a blank page, but if I go back and click "Windows Network" again it will allow me to browse.
 
Sometimes the first time I browse the Windows network I will get a blank page, but if I go back and click "Windows Network" again it will allow me to browse.
  
== Make sure SaMBa is NOT the Windows Master Browser ==
+
== Make sure Samba is NOT the Windows Master Browser ==
  
Often on a Windows office Network you already have a machine dedicated for the Master Browser and all that other Windows stuff that I've been slowly forgetting. A default install of SaMBa server might sometimes take over as the Master which may not be desirable. Having multiple local master browsers result in each server competing for browsing election requests. There should be only one local master browser per subnet.
+
Often on a Windows office Network you already have a machine dedicated for the Master Browser and all that other Windows stuff that I've been slowly forgetting. A default install of Samba server might sometimes take over as the Master which may not be desirable. Having multiple local master browsers result in each server competing for browsing election requests. There should be only one local master browser per subnet.
  
 
<pre>
 
<pre>
Line 137: Line 137:
 
<pre>
 
<pre>
 
//192.168.2.14/Shared\040Docs /media/shareddocs cifs auto,user=YOUR_WINDOWS_LOGIN,password=YOUR_WINDOWS_PASSWORD,rw,gid=admin,file_mode=00666,dir_mode=00777 0 0
 
//192.168.2.14/Shared\040Docs /media/shareddocs cifs auto,user=YOUR_WINDOWS_LOGIN,password=YOUR_WINDOWS_PASSWORD,rw,gid=admin,file_mode=00666,dir_mode=00777 0 0
 +
</pre>
 +
 +
== Simple smb.conf ==
 +
 +
<pre>
 +
[global]
 +
    security = share
 +
    domain master = no
 +
    local master = no
 +
    preferred master = no
 +
    os level = 0
 +
 +
[sde1]
 +
    comment = Public shared folder on Linux server
 +
    path = /media/sde1
 +
    public = yes
 +
    writable = yes
 +
    locking = no
 +
    guest ok = yes 
 
</pre>
 
</pre>

Revision as of 09:18, 2 September 2010

Mount a Windows share on Linux

It's pretty easy to mount a Windows network share on Linux. The `mount` command supports filesystem type cifs (and smbfs).

You may need to resolve your Windows \\server name to an IP address. I find this easier than trying to deal with the Windows names. The following examples show how to mount a Windows folder share named \\server\SharedDocs, and pretends that \\server resolves to 192.168.2.14.

This shows a mount using cifs:

mkdir shareddocs
sudo mount -t cifs -o user=Guest //192.168.2.14/shareddocs shareddocs

This shows a mount using old style smbfs:

mkdir shareddocs
sudo mount -t smbfs -o username=Guest //192.168.2.14/shareddocs shareddocs

Make SMB mounts persistent by using fstab

Add the following to /etc/fstab and /media/SharedDocs will be automatically mounted when you reboot or run `mount -a`. The IP address, 192.168.2.14, may be replaced with the Windows server name. You may also need to set username and password.

Using cifs

//192.168.2.14/shareddocs /media/shareddocs cifs auto,username=guest,password=,rw,user 0 0

This shows a mount with a given group of admin and forced permissions for files and directories.

//192.168.2.14/shareddocs /media/shareddocs cifs auto,user=YOUR_WINDOWS_LOGIN,password=YOUR_WINDOWS_PASSWORD,rw,gid=admin,file_mode=00666,dir_mode=00777 0 0

Old style using smbfs

//192.168.2.14/shareddocs /media/shareddocs smbfs auto,username=guest,password=,rw,user 0 0

Browse with smbclient

Note: don't put a trailing slash on the share name!

smbclient -UGuest //192.168.1.1/SharedDocs

Browsing Windows workgroups in Nautilus fails with a timeout

The root cause of this error is probably due to your DNS. You may have it set to OpenDNS or to some other "smart" DNS server that tries to guess what you meant or serves you a search page instead of just failing the way DNS is supposed to.

Samba tries to search for Windows shares through a few different methods. It first looks up names in DNS. If that fails then it tries localnet broadcasts to see if any machines answer. But if you have a "smart" DNS, then the lookup will not actually fail, so Samba will never fall-back to using broadcast lookups. Instead you will just get a timeout.

If you can't fix your DNS then you can change the name resolution order that Samba uses. Edit the file, /etc/samba/smb.conf and find the name resolve order line similar to this:

; name resolve order = lmhosts host wins bcast

Your values may be slightly different. Change this line so that it is uncommented and the resolve order puts host at the end of the list:

name resolve order = lmhosts wins bcast host

You may need to start any process that uses Samba including any of the horrible 'gvfs' processes. Sending a HUP signal is usually good enough.

pkill -HUP smb

Sometimes the first time I browse the Windows network I will get a blank page, but if I go back and click "Windows Network" again it will allow me to browse.

Make sure Samba is NOT the Windows Master Browser

Often on a Windows office Network you already have a machine dedicated for the Master Browser and all that other Windows stuff that I've been slowly forgetting. A default install of Samba server might sometimes take over as the Master which may not be desirable. Having multiple local master browsers result in each server competing for browsing election requests. There should be only one local master browser per subnet.

[global]
domain master = no
local master = no
preferred master = no
os level = 0

Errors

mount_data version 1919251317 is not supported

If you get an error something like this:

smbfs: mount_data version 1919251317 is not supported

then you don't have the smbfs module loaded. Under Ubuntu this is pretty easy to fix. Just run:

sudo apt-get install smbfs

mount error 6

If you get an error like this:

mount error 6 = No such device or address
Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)

then you probably used the wrong share name. The remote share does not exist.

Share a Linux directory on a Windows network

This provides read/write for everyone on the given disk named sde1 and mounted under /media/sde1. Put this in in /etc/samba/smb.conf then restart samba.

[global]
    security = share
[sde1]
    comment = sde1 on Linux server
    path = /media/sde1
    public = yes
    writable = yes
    locking = no
    guest ok = yes  

Samba Spaces in directory filename

If you have directory path that has a space in it then here is how you set this in /etc/fstab. For example, say the Windows shared directory had a space in the name such as "Shared Docs" instead of "shareddocs". Use '\040' instead of a space.

//192.168.2.14/Shared\040Docs /media/shareddocs cifs auto,user=YOUR_WINDOWS_LOGIN,password=YOUR_WINDOWS_PASSWORD,rw,gid=admin,file_mode=00666,dir_mode=00777 0 0

Simple smb.conf

[global]
    security = share
    domain master = no
    local master = no
    preferred master = no
    os level = 0

[sde1]
    comment = Public shared folder on Linux server
    path = /media/sde1
    public = yes
    writable = yes
    locking = no
    guest ok = yes