Installing and configuring basic Samba service in Ubuntu

From Notes_Wiki

Home > Ubuntu > Configuring Samba service in Ubuntu > Installing and configuring basic Samba service in Ubuntu

Basic information

Installation

Install samba, samba-swat and ldap based authentication for samba using:

sudo apt-get -y install samba samba-common smbclient gosa gosa-plugin-samba ldap-account-manager ldapscripts sadms smbldap-tools swat system-config-samba samba-doc samba-doc-pdf

Note:

  • You can enter kerebros values as 'localhost' everywhere, unless you actually know what value to configure.


About configuration file

In the default samba.conf file comments, both semi-colon(;) and hash(#) are used at various places. The significance of these commenting characters is:

  • ';' indicates suggested different default for particular value.
  • '#' indicates that default value is being used, but user should know about it


Testing configuration

Use command 'testparm' to check new samba configuration. Using 'testparm -s smb.conf.master > smb.conf' to generate smb.conf is recommended for better performance.


Documentation

Find documentation for samba at '/usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/'



Service configuration

  • To start samba in Ubuntu
    sudo service smbd start
  • To stop samba service
    sudo serivce smbd stop
  • To enable samba service for startup
    sudo update-rc.d smbd defaults
  • To disable samba service from startup
    sudo update-rc.d -f smbd remove



Guest access configuration

Basic guest configuration

Sections in smb.conf

smb.conf file has four different types of sections:

  • [global]
  • [homes]
  • [printers]
  • and everything else

[global] section allows in setting default values for all other sections. [homes] section comes into effect if no share-name matches with the request. In such cases requested share is matched against usernames and if a matching user is found, home folder for the user is used as share path (by default). This allows creating share for home folders for all users.


Readonly share

To create a read-only share with guest access use following steps:

  1. Rename '/etc/samba/smb.conf' to '/etc/samba/smb2.conf'
  2. Create new '/etc/samba/smb.conf' with following contents:
    [global]
    workgroup = ClipCard
    server string = ClipCard File Sharing Server
    netbios name = ClipCard
    log file = /var/log/samba/log.%m
    max log size = 1000
    security = share
    [samba_shared]
    path=/samba_shared
    read only = yes
    guest ok = yes
  3. Create folder for sharing files in read-only mode using 'sudo mkdir -p /samba_shared/1'
  4. Allow everyone full-access on created folder using 'sudo chmod -R 777 /samba_shared'. Note that 777 is not required for read-only share. 555 would also suffice.
  5. Restart samba service to take new configuration into effect using 'service smbd restart'
  6. Try to connect to created share using Guest username and no password using 'smbclient //127.0.0.1/samba_shared -U%'


Writeable share

  1. Edit file created in previous section and change value of 'read only' to 'no'.
  2. Restart samba using 'service smbd restart'
  3. Try smbclient again and try to upload a file using 'put <file>'


Configuring username and password based access

To configure authenticated username and password based access to Samba shares use:

  1. Add or modify lines in smb.conf to include:
    security = user
    passdb backend = tdbsam:/etc/samba/private/passdb.tdb
    idmap config * : backend = tdb
  2. For a share such as [samba_shared] set 'valid users' option as:
    [samba_shared]
    ...Other options...
    valid users = saurabh
  3. Note that 'guest ok = yes ' along with 'valid users' is contradictory and in such cases 'valid users' setting takes precedence.
  4. Use 'mkdir -p /etc/samba/private' to create a private folder.
  5. Use 'service smbd restart' to restart samba
  6. Use 'smbpasswd -a saurabh' to add saurabh user to samba tdbsam database.
  7. Try to access share using:
    smbclient -U saurabh //127.0.0.1/samba_shared



Home > Ubuntu > Configuring Samba service in Ubuntu > Installing and configuring basic Samba service in Ubuntu