Setting up Samba

To install SAMBA use sudo apt-get install samba, Irrespective of the OS, I always have a dave user. So what I usually do is share out my Linux home directory on the file server so it\’s available to any other machine on the network logged on as me.

The file you need to edit is:

/etc/samba/smb.conf

Look for [homes], you should see something like:

;[homes]

;   comment = Home Directories

;   browseable = no

The semicolons are commenting out the 3 lines, I replaced the above with:

[homes]\r\n

comment = Home Directories

path = %H/files

browseable = no

writeable = yes

create mask = 700

directory mask = 700

invalid users = root bin daemon nobody named sys tty disk mem kmem users

Rather than sharing out the /home/dave directory, this shares out a sub directory called files. This is just for tidiness as there are a lot of hidden files in the former that clutter up windows explorer if you have it set to show hidden files.

Use:

sudo /etc/init.d/samba restart

to restart the samba service with the new settings.

Now I need to create my files directory, this is simply a matter of:

cd ~

mkdir files

The cd ~ moves me back to my /home/dave directory so I create the files directory in the right place.

Finally:

sudo smbpasswd -a dave

adds a samba user for dave. Samba has it’s own set of users separate from the OS, this command just creates a new samba user. You will be prompted for a password, I use the same password for samba as I use for logging onto the machine (and my windows box for that matter).

From a windows box, I can now navigate to \\server IP\dave where server IP is the IP address of my server.

NOTE: There’s a chance that you might have to restart the samba service last. I forgot to create the files directory and one of my attempts to fix the problem was to restart the server after creating the samba user (it’s done before in the above instructions).

This setup is pretty basic. Things I’d like to do in addition would be:

  • Create a read only share that’s available to anyone to store media for viewing on any machine on the network, irrespective of the user logged on. Although selected users should have permissions to upload,change and delete files.
  • Create a share that can be updated by anyone. This would be useful for backing up files from pocket PC devices on the network that don’t seem to be able to log on as a particular user.

I’ve had a brief look at SME server which does all sorts of cool stuff, including being a domain controller for windows boxes. Currently I have to keep my windows, linux and samba passwords in sync, SME server would provide a single central mechanism for keeping everything in line. Hopefully I’ll cover this in a later post.

Setting up your file server for multiple users – Part 1

Ok, just a few points to make before we start:

The whole point of this post (and probably the next couple) is to make a useful network file server from an old PC running Ubuntu Linux. The version I’m now running is 7.10 (gutsy  gibbon – I think!).

  • You should have a Linux box already purring away nicley and you should have installed Samba and optionally SSH (for remote admin or if you’re running your box headless.
  • You have an account that can use <strong>sudo</strong> to run root (administrative) commands.
  • I’ll initially jump over the relatively simple matter of sharing your home folder and look at creating shares that can be accessed by many users.
  • I couldn\’t have done this without the help of the guys at my local Linux User Group who seem to be on hand 24 hours a day to respond to my daft questions.

Ok, here goes:

Log onto your system, either at the console or remotely via SSH (e.g. using puTTY or another fine emulator).

  • Create a suitable named group, for this example we’ll use “lowtowndogshome”.

sudo groupadd lowtowndogshome

  • Create the required directory tree, again for this example, I’m going to create a directory called “shared” in the root of the filesystem.

sudo mkdir /shared

  • Change group ownership of the directory (or directories) you just created to the group you created earlier, note that the owner is still root, this seems to be ok.

sudo chgrp lowtowndogshome /shared

  • Change permissions so that the owner and group members have full access to the directory.

sudo chmod 770 /shared

Each Linux user that needs access to the new directory should be assigned to the new group, make sure that you use the -a option on the command below otherwise bad things can happen! I’m using a local account called dave. See below for the command line required to create a new user.

sudo usermod -a -G lowtowndogshome dave

If you’re logged on as the user you’ve just given group membership to, you’ll need to log off and back on again for the change to take effect.

Now when you’re logged on as the user(s) who are now in the new group you should be able to navigate to the new directory and create, modify and delete files.

cd /shared

touch fred.txt

rm fred.txt

None of the above commands should result in an error.

To create a new user use:

sudo useradd -m fred

fred is the name of the new user, the -m option makes Linux create a home directory for the user (e.g. /home/fred), this is useful if you also want to share the users home directory (see a subsequent post, coming soon).

Setting up your file server for multiple users – Part 2

Assuming you’ve done everything in the previous post, all you need to do now is set up your samba service:

  • Backup your existing configuration.

sudo cp /etc/samba/smb.conf smb.conf.original

  • Edit your smb.conf file, add something resembling the following on the line above the [homes] section.

[share]

comment       = Shared files

browseable    = yes

read only     = no

writeable = yes

guest ok      = no

path          = /shared

invalid users = root bin daemon named sys tty disk mem kmem users

  • Create a samba account for each Linux user that will want to see this directory from a windows (or other Linux) machine. You will be prompted for a password, for my dave user, I use the same password that I use on my windows box but this doesn’t have to be the case I suppose.

smbpasswd -a dave

  • You may have to restart the samba service for changes to take effect, this is always a good idea if you\’re having problems.

sudo /etc/init.d/samba restart

Now from a windows machine, logged on as a user with the same username (and password in my case) I can navigate to \server_address\share and drop files ’till my hearts content.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.