Online Book Reader

Home Category

Running Linux, 5th Edition - Matthias Kalle Dalheimer [308]

By Root 1243 0

#

# Script to start/stop samba

# Locate this in /sbin as a file called 'samba'

RCD=/etc/rc.d

if [ z$1 = = 'z' ]; then

echo $0 - No arguments given; must be start or stop.

exit

fi

if [ $1 = = 'start' ]; then

${RCD}/nmb start

${RCD}/smb start

${RCD}/winbind start

fi

if [ $1 = = 'stop' ]; then

${RCD}/smb stop

${RCD}/winbind stop

${RCD}/nmb stop

fi

if [ $1 = = 'restart' ]; then

${RCD}/smb stop

${RCD}/winbind stop

${RCD}/nmb stop

sleep 5

${RCD}/nmb start

${RCD}/smb start

${RCD}/winbind start

fi

exit 0

A sample startup script for a Red Hat Linux system is shown in Example 15-2. This file could be located in the directory /etc/rc.d and can be called samba or smb. A similar startup script is required to control winbind. If you want to find more information regarding startup scripts , please refer to the packaging section of the Samba source code distribution tarball. The packaging files for each platform include a startup control file.

Example 15-2. A sample Samba control script for Red Hat Linux

#!/bin/sh

#

# chkconfig: 345 81 35

# description: Starts and stops the Samba smbd and nmbd daemons \

# used to provide SMB network services.

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ ${NETWORKING} = "no" ] && exit 0

CONFIG=/etc/samba/smb.conf

# Check that smb.conf exists.

[ -f $CONFIG ] || exit 0

# See how we were called.

case "$1" in

start)

echo -n "Starting SMB services: "

daemon smbd -D; daemon nmbd -D; echo;

touch /var/lock/subsys/smb

;;

stop)

echo -n "Shutting down SMB services: "

smbdpids=`ps guax | grep smbd | grep -v grep | awk '{print $2}'`

for pid in $smbdpids; do

kill -TERM $pid

done

killproc nmbd -TERM; rm -f /var/lock/subsys/smb

echo ""

;;

status)

status smbd; status nmbd;

;;

restart)

echo -n "Restarting SMB services: "

$0 stop; $0 start;

echo "done."

;;

*)

echo "Usage: smb {start|stop|restart|status}"

exit 1

esac

Validating that Samba is running. Now that you have Samba installed, configured, and running, try using the smbclient command to list shared resources (the example given here is from an office network on a day when only two people were at work):

linux:~ # smbclient -L localhost -U%

added interface ip=172.16.1.3 bcast=172.16.1.255 nmask=255.255.255.0

Domain=[MIDEARTH] OS=[Unix] Server=[Samba 3.0.20]

Sharename Type Comment

--------- ---- -------

archive Disk Full Archive Files

print$ Disk Printer Drivers

netlogon Disk Network Logon Service

profiles Disk Profile Share

IPC$ IPC IPC Service (Main Server)

ADMIN$ IPC IPC Service (Main Server)

kyocera Printer FS-C5016N

Domain=[MIDEARTH] OS=[Unix] Server=[Samba 3.0.20]

Server Comment

--------- -------

AURORA Moberg's Magic Machine

MERLIN Main Server

TINKERBELL Mel's Laptop

Workgroup Master

--------- -------

MIDEARTH MERLIN

This output demonstrates that a null-session connection could be made to the Samba server. The null session is one that uses no username and no password; it depends only on the availability of the guest account, which is usually called nobody in the /etc/passwd file.

If this validation step fails, the cause is usually either that a firewall is blocking the Samba network traffic or that the guest account could not be found in the /etc/passwd file.

Adding users

Network users must be authenticated by Samba before they can access shares. The configuration we are using in this example employs Samba's "user-level" security. This means that users are required to provide a username and password that must match those of a Samba account on the Linux host system. The first step in adding a new Samba user is to make sure that the user has a Linux system account, and, if you have a [homes] share in your smb.conf, that the account has an existing home directory.

The tool most frequently used to add user accounts to a Linux system is called useradd.

linux:~ # useradd -musername

Samba uses its own password file. It uses the Windows

Return Main Page Previous Page Next Page

®Online Book Reader