Gentoo Wiki


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc



Samba is a free software implementation of Microsoft's networking system. As of version 3, samba not only provides file and print services for various Microsoft Windows clients but can also integrate with a Windows Server domain, either as a Primary Domain Controller (PDC) or as a Backup Domain Controller. It can also be part of an Active Directory domain. In this HOWTO I will show you a quick and dirty setup of Samba. The reason I created this manual is because when I needed to setup samba quickly (just for few shares and one user), I spent about 2 hours reading lots of pages about Samba configuration. If you need a more detailed Samba manual, read HOWTO_Setup_Samba


Code: Installing Samba
emerge samba

Samba has a lot of USE flags. Mostly all you need is: cups and automount. Cups is for printer sharing (I will not explain that in this manual) and automount is for automounter, to automatically mount your shares (not boot, but on-the-fly). Set these flags to avoid recompilation of Samba in the future.

Server Side


Configuration file for Samba server is /etc/samba/smb.conf. Open it with your favorite text editor and let's edit. In the beginning of file (in global section) you'll see the following:

File: /etc/samba/smb.conf
       workgroup = HOME 
       netbios name = SAMBA
       server string = Samba Server %v
       map to guest = Bad User
       log file = /var/log/samba/log.%m
       max log size = 2000
       socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
       preferred master = No
       local master = No
       dns proxy = No
       security = User

# Share
       path = /home/john
       valid users = john
       read only = No
       create mask = 0644
       directory mask = 0755

The workgroup name needs to be the workgroup of your Windows computers, or your domain name. The netbios name is what will appear when you access the Linux computer from Windows. I am currently running a Windows domain with this setup, so I have the preferred master and local master set to no to avoid both servers from attempting to be the master browser. This will eliminate network conflicts on your Windows computers that can cause network-related outages.

We also added a share named Data here. Change the path to that what you want to share. Read only - set if directory will be writable or read only.

Adding users

The next step is to add users by the following command:

Add user if you haven't created it yet for the gentoo system.

Code: Installing Samba
useradd -c "John Lennon" john

Set samba password to that user:

Code: Installing Samba
smbpasswd -a john

you will be asked to enter password twice

Next, run the testparm command to ensure that the configuration file is valid. If it returns no errors, restart Samba with the command /etc/init.d/samba restart

Client Side

On Unix Machine

Kernel Requirements for Clients

To mount shares you need to have kernel SMB file system support, compiled-in or as a module.

Switch to the directory of the current kernel source and launch the menuconfig utility by running: cd /usr/src/linux && make menuconfig

Linux Kernel Configuration: Required options for Samba
File systems  --->
  Network File Systems  --->
    <*> SMB file system support
    <*> CIFS support

Detect Shares

Before you can mount a share you must know where it is. List the shares on a foreign host with the following command, replacing <hostname> with the name of the host: smbclient -L <hostname or ip> -U%

You'll see something like this:

Code: Shares
        Sharename       Type      Comment
        ---------       ----      -------
        Data            Disk      
        IPC$            IPC       IPC Service
        ADMIN$          IPC       IPC Service

Here we can see a share names "Data" which we have configured already on our server. Now let's asume that we have three computers in the network. One server, another one with gentoo system, and third with Windows system. Firstly we will try to mount a share from our server to the computer with gentoo os.

Mounting Unix share

Code: Mouting Unix Share
mount //<Machine name or IP>/<shared folder> /<mountpoint> \
 -o "username=john,uid=<uid>,iocharset=cp1257,dir_mode=0700"

You will be promted for the password of user john.

Mounting Windows shares

Now let's try to mount a Windows share either from the server or from the third computer with gentoo.

To access the Windows shares on the network, you can mount them quite like standard Unix mounts. Note that the SMB fstype is deprecated in favor of CIFS. You should use the mount command instead of smbmount.

Using CIFS

Mount the share with using the following command, replacing <shared folder>, <mountpoint>, <user> and <uid> with the relevant values. <uid> usually is 1000.

Code: Command for mounting shares using CIFS
mount -t cifs //<windows machine name>/<shared folder> /<mountpoint> \
 -o "username=<user>,uid=<uid>,iocharset=cp1257,dir_mode=0700"

The charset cp1257 may be not correct, or even cause a share not to mount at all, depending on you Windows setup. This particular charset is used in a Lithuanian production environment. You may want not to use this option at all.

NOTE: -t cifs argument does not work with NT type Windows. If you are still using Windows 98 or above, remove this argument.
NOTE: Windows 2003 will not work without cifs at all.


If above Mountings work then you are ready to add some lines to /etc/fstab to auto-mount shares from machines that are always on and always connected (like your DVD-ROM)

File: /etc/fstab
//<windows machine name>/<shared folder>   /<mountpoint>   smbfs   username=<user>,password=<pass>,uid=1000,umask=000   0 0
//<windows machine name>/<shared folder>   /<mountpoint>   cifs   username=<user>,password=<pass>,uid=0,gid=1000,file_mode=0664,dir_mode=0775,auto   0 0
//<gentoo server machine name>/<shared folder>   /<mountpoint>   smbfs   username=<user>,password=<pass>,uid=1000,umask=000   0 0

Note: to mount shares with spaces, use "\040" without the quotes in place of the space.

A quick explanation:

File: /etc/fstab example using credentials file
//<windows machine name>/<shared folder>   /<mountpoint>   smbfs  auto,credentials=/root/.windowscredentials,uid=1000,umask=000,user  0 0
//<gentoo machine server name>/<shared folder>   /<mountpoint>   smbfs  auto,credentials=/root/.servercredentials,uid=1000,umask=000,user  0 0

/root/.<gentoo or windows>credentials takes the form

File: /root/.credentials example

and make the file only be read/writable by root by running: chmod 600 /root/.windowscredentials

Once the /etc/fstab file is edited and /root/.credentials file created and secured, everything can be tested using mount -a with no need to reboot as the /etc/fstab is used at boot time. using -a option tells to mount all of the mount points in /etc/fstab and write to the /etc/mtab accordingly. If mount ran into any errors reading the /etc/fstab file it should automatically output an error message with good description, e.g.: invalid share name, access denied, invalid or non-existing mount point.

NOTE: You can create as many credentials as you want, just don't forget to chmod them and use each one for it's own share.

Optionally you can use mount <mountpoint> to mount just the mountpoint you just added to /etc/fstab. umount <mountpoint> will unmount the mountpoint.

Starting Samba on Boot

To start samba on boot, add it to the default runlevel by running: rc-update add samba default Do this on all gentoo machines.

On Windows Machines

Now you're ready to test Samba on a Windows computer, you can either map a drive to the Samba server or access the drive using the Start-Run command and typing \\Samba\data, "Samba" being the server name and "data" being the shared folder.

If you do not know how to share directories and what is map drive go to google and search for "Windows Map drive" "Windows share directory".

If you can ping a windows host, but not mount a share, make sure that file and printer sharing is not disabled in the corresponding connection's settings. Firewalls may also cause some problems.


If using more or less strict iptables setup, you may have to do the following (substitute eth1 with your interface):

Code: Pass Windows/Samba, Input and Output, TCP, eth1
iptables -A INPUT  -p tcp -m tcp -i eth1 --dport 137:139 -j ACCEPT
iptables -A INPUT  -p tcp -m tcp -i eth1 --dport 426 -j ACCEPT
iptables -A INPUT  -p tcp -m tcp -i eth1 --dport 445 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp -o eth1 --dport 137:139 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp -o eth1 --dport 426 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp -o eth1 --dport 445 -j ACCEPT

or just

Code: Pass everything, eth1
iptables -A INPUT -i eth1 -j ACCEPT
iptables -A OUTPUT -i eth1 -j ACCEPT


I still do not have write permissions to my shared directory on unix machine

Try this: chown -R john /path/to/your/share replace user with yours, at least this solved problem for me

You can find troubleshooting information at the end of HOWTO_Setup_Samba manual.


This setup serves a small network or a home network. For a larger user base and more complex network configuration, you may want to use the this: HOWTO_Setup_Samba


If you have some requests or author forgot something to add, please write suggestions here.

1. Automounter + Samba

2. User mounting after boot time

Credits - Quick and Dirty Samba Setup
HOWTO_Setup_Samba - Very detailed Samba setup

Manual created by Holms. I hope that this manual saved some time for you. =) Edited by DSHugo.

Retrieved from ""

Last modified: Sat, 06 Oct 2007 09:24:00 +0000 Hits: 6,046