Samba

From Megazirt Wiki
Jump to: navigation, search

Samba is used as my protocol of choice for file and print sharing; because of the mix of operating systems on my network this seems to be the only real choice at the moment without replacing the Windows clients. The settings here are mainly for setting up the Linux and Mac OS X clients / servers.

Linux Clients

  • Setting up AutoFS

Some of the linux guides out there seem to mention two ways to automatic mount Samba shares, either adding an entry in fstab or using autofs. While fstab seems easiest to setup, AutoFS is suppose to mount and unmount shares as needed to conserve bandwidth and gain performance. AutoFS is also good for laptops, in case you can't mount on start up (when away from home.) (This guide stems from [Wiki CentOS Tips and Tricks on Windows Shares]

Install AutoFS, assuming Samba / Windbind is already setup.

su root -c "yum install autofs -ty && chkconfig --add autofs"

Create a local mount point on the client, all the shares will branch from this folder

mkdir /samba

In Fedora 15, there seems to be some slight changes to the default configuration (pre 15) that seem slightly backwards to how I want things setup. I like to have my mapped directory always displayed when in the parent folder without specifying the maps in the address bar, and I like to shorten the timeouts. This is done my editing the /etc/sysconfig/autofs file. Browsing is fixed by changing a string around line 32 to read...

#BROWSE_MODE="no"

Note also that this file allows debugging to be turned on in case of trouble. The log uses /var/log/messages.


Now delete the auto-generated configs which where made during yum installation, we don't need the demo stuff. Note that in the /etc directory is also files called auto.smb, auto.misc and auto.net which are needed and shouldn't be deleted.

rm /etc/auto.master

Create a new /etc/auto.master referencing the local mount point we created. I have added the timeout option so my computer doesn't freeze if the folder is accessed when my laptop is disconnected...

/samba /etc/auto.samba --timeout=5

This sets up the master autofs configuration file to use the /etc/auto.samba file for mounting whenever /samba is accessed. In this file I have two sub folders on the mount point. The "home" mount is the root of all user directory's, but user access will be restricted using Samba permissions on the server. I could even map this further down the tree with another ${HOME} string as ://tux.megazirt.local/users/home/${HOME}.
The "Storage" is a general pubic share I have and doesn't need any passwords. I fill the /etc/auto.samba file with...

storage -fstype=cifs,rw,fmask=0777,dmask=0777,uid=alan,gid=alan  ://tux.megazirt.local/storage
users   -fstype=cifs,rw,credentials=${HOME}/.smbcred.txt,uid=${UID},gid=${EUID} ://tuz.megazirt.local/users

Notice that we act like two user directory's apply here, there is the user on the server (smbcred,) and the permissions shown on the 'storage' line that states that links the remote servers user to the local 'alan' user. Pew, it's getting confusing.

So based on my users line, for the credentials, I then add a credentials files in the users home directory. The general format is ~alan/.smbcred.txt with the content as follows.

username=DOMAIN\Alan
password=NotMakingMyPasswordPublic!

There must surely be some better way of specifying the login password with SSO, as I use winbind authentication to log in anyway, but I don't know of how. Don't forget to chown and chmod the .smbcred.txt, so no one else can view it.

chown alan:alan ~alan/.smbcred.txt
chmod 400 ~alan/.smbcred.txt
  • Directory Sync

Once I have the home folder samba mount on my laptop I want to be able to synchronise my networked home/user/documents folder with the Linux desktop. The home folders I have where created for Windows clients with the Windows directory structure, so I have to do some trickery to get the Linux sync with the Linux structure. My original way of syncing was with Unison. Unison has an excellent interface and worked well, but development has stopped and it was very slow; so I've moved to rsync. But if you do have trouble with rsync, try Unison. In cause it isn't installed already, install rsync and grsync,

su root -c "yum install rsync grsync -ty"

grsync is a nifty but simple GUI for setting up rsync. It doesn't save a batch file, but rather allows you to start syncs within the GUI. What's also handy is it will show you the command line is uses for rsync, which you can just copy into your own script or into cron.

Personal tools