Saturday, July 21, 2012

Replacing WHS 2011 with Ubuntu Server 12.04 (Part 5 - Install and configure Samba)

While I personally spend the most time on a MacBook both personally and professionally, both my wife and I spend a great deal of time with Windows as well. As such, it is important that the home directories and shared data on the home server be accessible to both Windows, Linux and MacOS. This is especially true as the home server must also serve as a backup repository for the several windows machines in the house as well.

Thus, it's time to configure Samba. As the basis for my smbd config I primarily used: http://www.sitepoint.com/ubuntu-12-04-lts-precise-pangolin-file-sharing-with-samba/ but there are a plethora of resources for configuring Samba and I've only scratched the surface of what's available.

$ sudo apt-get install samba

[global]
    unix charset = UTF-8
    # -------------------------------------------
    # DEFINE YOUR WORKGROUP AND COMPUTER NAME HERE
    workgroup = WORKGROUP
    server string = homeserver-s
    netbios name = homeserver-s
    # -------------------------------------------
    dns proxy = no
    name resolve order = lmhosts wins bcast host
    # -------------------------------------------
    # IF YOU SET BIND INTERFACES TO YES, TO AVOID LOG ERRORS,
      # MAKE SURE YOUR SAMBA SERVICE STARTS AFTER THE ETHERNET CARD IS SWITCHED ON
    # bind interfaces only = no
    # bind interfaces only = yes
    bind interfaces only = no
    # ADD THE ETHERNET CARD AND IP ADDRESSES YOU ALLOW
    interfaces = eth0 127.0.0.0/8 192.168.1.0/24
    # -------------------------------------------
    # SAMBA LOG FILES
    log file = /var/log/samba/log.%m
    max log size = 1000
    syslog only = no
    syslog = 0
    # -------------------------------------------
    panic action = /usr/share/samba/panic-action %d
    # LIMIT ACCESS TO USERS ONLY
    security = user
    # USING TDBSAM
    encrypt passwords = true
    passdb backend = tdbsam
    obey pam restrictions = yes
    unix password sync = yes
    passwd program = /usr/bin/passwd %u
    passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
    pam password change = yes
    map to guest = bad user
    usershare allow guests = no
    # -------------------------------------------
    # INCLUDE THIS SECTION TO DISABLE PRINTERS/CUPS ONLY
    load printers = no
    printing = bsd
    printcap name = /dev/null
    disable spoolss = yes
    # -------------------------------------------
    # DIRECTORIES
    # -------------------------------------------
    # ENABLE HOME FOLDER ACCESS
    [homes]
        comment = Home Directories
        browseable = no
        writable = yes
        valid users = %S
    #    valid users = MYDOMAIN\%S
        create mask =0755
        directory mask =0755
    # -------------------------------------------
    # EXAMPLE FOLDER WITH LIMITED ACCESS, UNCOMMENT AND CUSTOMISE AS NECESSARY
    #[example]
    #   comment = example share folder on my-computer-name
    #   path = /foldername/foldername/
    #   browseable = yes
    #   guest ok = no
    #   writable = yes
    #   create mask = 0755
    #   directory mask = 0755
    #   valid users = @your-username
    #   force group = your-username-or-group
    #   force create mode = 0755
    # -------------------------------------------
    # -------------------------------------------
[Videos]
   comment = Transcoded movies and television shows
   path = /data/external/videos
   browseable = yes
   guest ok = no
   writable = yes 
   valid users = @staff 
   force group = staff
   force create mode = 0664
   force directory mode = 0775

With the shares configured and created, restart smbd and nmbd.
$ sudo server smbd restart && sudo service nmbd restart

Before user authentication will work, the following needs to be run for each user that will be granted access. The user account also needs to be a member of the staff group, which is effectively power users on my system.

$ smbpasswd -a new-username-here
 
This command will prompt for a smb password. As configured I'm assuming the unix and smb passwords are the same.

 

No comments: