Setting up Samba
From ArchWiki
| i18n |
|---|
| Dansk |
| German |
| English |
| Czech |
| Romanian |
| 简体中文 |
| 正體中文 |
| Italiano |
Contents |
[edit] Installation
First of all - make sure you have the workgroup of the home network you wish to share over. This will come into play later.
Next install samba.
pacman -Sy samba
[edit] Configuration
Now - to share the actual data. Still as root, change to the directory which holds the smb.conf file (This file holds samba's configuration settings as well as the share information)
cd /etc/samba
During the Samba installation a default configuration file is saved. Make a copy of this file. The configuration file smb.conf will be used by Samba.
cp smb.conf.default smb.conf
Now begin editing the file
nano smb.conf
The first section is the Global Parameters section. This refers to the "blanketing" options for Samba - much of your editing will be done here. Here is my smb.conf's Global Parameters Section for reference:
#Global Parameters workgroup = HOME netbios name = Bennett-DSLIN encrypt passwords = yes
The workgroup name is what it says it is, what workgroup you want this machine to be a part of. (The default in Windows XP is MSHOME and WORKGROUP.)
The "encrypt passwords" option should be kept at "yes" (when this option is not set defaults to yes). This may change if your other machine runs Windows 95 or Windows 98, as their earlier builds use unencrypted passwords.
The "netbios name" is how you want this machine to appear in the "Network Neighborhood" (or "My Network Places" in Windows XP).
[edit] Share examples
Now to set up the shares. The simplest share would be one in which the user can access and write his own home folder. Consider shares ([homes], [music]...) as some kind of a profile which you can configure and mount later on.
[homes] browseable = no read only = no
If you want everyone to see the files, but only certain groups to be able to write (say everyone can view, but only the staff group can write) then the section would look like this:
[homes] public = yes writable = yes write list = @staff
If you want regular Windows users to see a "clean" home page (and not be confused by all those dot files (e.g. ~/.bashrc), then the section would look something like this:
[homes] path = /home/%u/smb browseable = no read only = no
Be sure to add 'smb' to everyone's home directory. Also add 'smb' to the /etc/skel folder so all new users get an 'smb' added to their home directory, automatically:
mkdir /etc/skel/smb
Moving on to shares other than the home directory isn't much harder, as there are really only two more commands that did not apply to the homes. These are the path command and the valid users. Looks like this:
[music] path = /mnt/windows/Music/ browseable = yes read only = yes valid users = Bryan, Michael, David, Jane
The Path is obviously where on the harddrive the share is. Pretty simple, no?
The valid user command lets Samba know which users have the ability to even log in to the share. Again - pretty simple, although this creates a bit more work for us. Please keep in mind that these user names MUST coincide with users on the linux box and SHOULD coincide with users on the Windows box.
Another example: an anonymous read-only share.
[Public] path = /pub public = yes read only = yes
[edit] Adding users
Once the smb.conf file is set up as you want it, save and exit the editor. (This is Ctrl+O in nano, followed by Ctrl+X)
Next We have to add the "valid users" to samba's user list. Do this by issuing
smbpasswd -a <username>
Follow its instructions, creating the password to be the same as the Windows password, and the user name the same as the Linux user. Once you have finished adding users, You are done (mostly). Samba users and their encrypted password are kept into /etc/samba/private/smbpasswd(5).
[edit] Usage
If you have not done so - start (or restart) the samba daemon by issuing the following as root:
/etc/rc.d/samba stop /etc/rc.d/samba start
If everything worked out you can add samba to your DAEMONS in /etc/rc.conf
DAEMONS=(syslog-ng network ... samba ...)
[edit] Windows client
Now - run upstairs to the other computer (or wherever it is ) and reboot. When it boots back up, login as one of the "valid users" and attempt to access your shares. You will need the password from the smbpasswd step to do so.
[edit] Linux client
Install package extra/smbclient for an ftp-like command line file transfer program.
[edit] smbclient
To display shares available on an server (no auth required):
$ smbclient -L <netbios_name> -U%
To connect to a share:
$ smbclient //<netbios_name>/<share> -U<username>%<password>
\ can be used instead of / but must be quoted to avoid interpretation by the shell.
| help [command] or ? [command] | show all available commands or give help about a specific command |
| put <local name> [remote name] | upload a file |
| get <remote name> [local name] | donwload a file |
| ls [mask] | list current directory content |
| cd [directory] | change current directory; without the argument print working directory |
| lcd <directory> | change local working directory |
| mget <mask> | download all files matching mask |
| mput <mask> | upload all files matching mask |
| recurse | enable recursive directory download/upload with mget/mput commands |
| prompt | toggle prompting on every single file or directory when using mget/mput commands. By default prompting is enabled |
| !<local command> | execute a local command and capture output |
[edit] mount
Manualy mounting and unmounting samba shares (you need root permissions to do this):
mount -t cifs //<netbios_name>/<share> /<mount_point> -o user=<username>%<password>
This is for the above example of netbios name "Bennett-DSLIN", and [homes] and [music] shares.
mount -t cifs //Bennett-DSLIN/homes /media/homes -o user=<username> mount -t cifs //Bennett-DSLIN/music /media/music -o user=<username>
For unmounting use umount:
umount /<mount_point>
There are two ways to allow non root users to mount arbitrary shares: install community/smbnetfs or make /sbin/mount.cifs setuid root.
[edit] Links
- Samba Samba (German) (archlinux.de)
- Official samba website
- Samba: An Introduction