Samba Tutorial

When you have several computers (whether you collect old machines, various family members "need" computers in their rooms, or you just don't throw old shit away), you inadvertaly end up with a linux machine or two. This usually starts off with an experiment (kewl people use linux, after all), and you're curious. If you're fortunate not to be turned away by hardware problems, you have a machine sitting in a room (perhaps yours) but you can no longer transfer shit to and from your computer, to the other window machines.

You know you could use FTP... but setting up an FTP server on each computer isn't just stupid, it's risky and pointless.

This is where Samba comes in. It's your new best friend. It can emulate a windows networked machine, it can emulate a NT domain server... it can do just about anything a windows computer can do. Only better.

Not only does it have excellent password managment (no more having people browser your shares because you assumed they needed your password), but it never mysteriously stops working, and bitches about privileges and "contacting your admin".

Getting samba is usually very simple. Whether it's apt-get install samba, rpm -ivh samba.rpm, or some other such way of fetching it, installing samba is a cakewalk.

Getting it to work can be tricky though.

First, I'll assume you have several computers connected via a router/hub, all with the same subnet and IP type (eg, 192.168.2.x)

You'll want to make your way to /etc/samba, and open up smb.conf

Change workgroup = to your workgroup. (workgroup = mshome), and move on. Nothing tough here, eh?

server string = Linux Server (or whatever you want) is useful, since usually the name that shows up under network neighborhood is something ridiculously long (Hostname Samba Server 1.3.53823, for example). Just call it what your hostname is.

Very important: hosts allow = 192.168.2.

If you use static IPs, and only want one or two computers to access this (and their IPs don't change!), you can use: hosts allow =

You don't want other jackasses connecting. Especially if, for some reason, you don't have a firewall (or have DMZ enabled on your router).

Make sure that: security = user encrypt passwords = no

Encrypt passwords is to make sure that anyone sniffing your network (especially if you use wireless, or your hub is in an insecure/public place). An example of this is if in your apartment building, there is free internet. Everyone is on the same network, so you have to be aware that some people might have nefarious urges. The problem with this is that WINDOWS DOES NOT USE ENCRYPTED PASSWORDS. You'd have to tweak the registry to do this, and I will not cover this (since I know one of you fucktards will mess up, and come crying to me to help you. And I'm lazy.)

Go down to where it shows 'home'. This way, you can hand out diffrent username/passwords for your shares, and they'll have their own private space to store stuff.

Below that, add something like:

comment = Place for everyone to see
path = /public
read only = no
public = yes

You'll want to make sure the permissions on this allows for reading and writing of the group 'users' (I'll get into this later).

Now you'll want to add your first two samba users. You'll also want them to be local system accounts as well.

useradd -G users -m -s /bin/bash userone
useradd -G users -m -s /bin/bash usertwo

-G users = sets group as users
-m = sets up a default /home/username directory, so they have a place to store files, and arn't just thrown out into the void when they try to log on.
-s /bin/bash = sets their shell. Things like proftpd need you to have a shell set as default, or you can't log in. I belive this is true for samba. If not, you can change that to /bin/false to make sure they *can't* log on, for security reasons. Either way, shouldn't be a problem.

passwd userone
passwd usertwo

(sets their passwords)

smbpasswd -a userone
[enter password]
smbpasswd -a usertwo
[enter password]

Now restart samba. In debian, this would be entering in: '/etc/init.d/smb restart' or '/etc/init.d/samba restart'

In slackware, '/etc/rc.d/rc.smb restart' or '/etc/rc.d/rc.samba restart'

I'm sure you can find it, it's usually in either of those two places, no matter the distro.

Now test it out! Go to a windows computer, and open up network neighborhood.

You should see your linux computer show up, clear as day. Go into it, enter in one of the users, and transfer some files.

In order to get files off of windows computers (this part if very cool), you can do one of two things.

1) Use what is, basically, a command-based FTP client for window shares
2) MOUNT the window shares (similar to map network drive in windows), and use those shares as if you had those drives inside your computer. Very nifty, and useful.

Instead of going to each computer, and finding it's IP, do this:

nmap 192.168.2.* > nmap.lan

When it's done, just cat nmap.lan (or open it up in an editor).

For each IP that is up, do the following:

smbclient -L $IP (where $IP is the ip address)

It will list the shares and workgroup that computer is a part of (along with the username, usually, of the user on the computer).

So try this:

smbclient \\\\\\c$ -U username (Administrator, or other)

Why the double slashes? Because linux handles that charachter diffrent than windows.

It should prompt you for a password. If you get it right, you're in!

Now navigate to a directory (cd test), and upload something.

put /etc/hosts

now grab something

get test2\whoknows.txt

See how that works? Great.

Want to transfer files w/o all the interactive shit?

smbclient \\\\c$ -U username -Tc backup.999.tar test2/ (note the diffrent between the charachter used after test2 above, and the test2 in this line)

This will great a file called backup.999.tar in test2 on the windows server. Remeber, / is correct in this case, even though it would usually be \ in windows.

Now let's mount a windows directory!

mkdir /mnt/localnetwork
mkdir /mnt/localnetwork/computer1
mkdir /mnt/localnetwork/computer2
mkdir /mnt/localnetwork/computer1/c
mkdir /mnt/localnetwork/computer1/d
mkdir /mnt/localnetwork/computer2/c
mkdir /mnt/localnetwork/computer1/d
mkdir /mnt/localnetwork/computer1/f

smbmount \\\\\\c$ /mnt/localnetwork/computer1/c -u username=timmy
smbmount \\\\\\d$ /mnt/localnetwork/computer1/d -u username=timmy
smbmount \\\\\\c$ /mnt/localnetwork/computer2/c -u username=edwards
smbmount \\\\\\d$ /mnt/localnetwork/computer2/d -u username=edwards
smbmount \\\\\\f$ /mnt/localnetwork/computer2/f -u username=edwards

There you have it. Now it's all orgainized, without having to clutter up your /mnt directory. (Assuming, of course, you can mount c$ and d$. This is only for Windows NT/2000/XP). If you don't share C (once again, NT/2000/XP do by default... yay for security!), you might have 8 little folders shared... and having them all in /mnt would be messy. Thus the entire /mnt/localnetwork/computer#/$share way of doing things.

If smbmount doesn't work, you can always try regular mount (useful for if you don't have samba installed yet, and still need to get some shit).

mount -t smbfs -o username=timmy \\\\\\c$ /mnt/dlablovesthecock

Of course, you'd need smbfs enabled, which most kernels DO have.

Another userful command is nmblookup, which I won't get in to much. Mess around with these two commands, and read the man pages.

nmblookup -A
nmblookup -M -- -

Smbtar is another command that I've heard, but havn't used yet. I'll update this page when I become more familar with it.