Hits : 4353

Samba :: Mini How To 


samba


http://www.samba.org/


Samba-HOWTO-Collection


Using Samba


top


Installation


$ wget -c http://gr.samba.org/samba/ftp/stable/samba-3.2.6.tar.gz
$ tar zxvf samba-3.2.6.tar.gz
$ cd samba-3.2.6/source
$ ./configure
$ make 
$ sudo make installl


Ένα πιο advance configuration:


$ ./configure --with-fhs --with-ldap --with-automount --with-smbmount --with-libsmbclient --with-winbind


Ως διαχειριστές:


# touch /usr/local/samba/etc/samba/smb.conf
# mv /etc/samba/smb.conf /etc/samba/smb.conf.old
# ln -s /usr/local/samba/etc/samba/smb.conf /etc/samba/smb.conf
# /usr/local/samba/sbin/smbd -D


top


Έλεγχος λειτουργίας


# /usr/local/samba/sbin/smbd -F -S


top


smb.conf


Το παρακάτω είναι ένα default share point.
Δεν περιέχει security αλλά είναι λειτουργικό.


Προσοχή εάν θέλετε να μπορούν να γράφουν στον κατάλογο πρέπει ο χρήστης
nobody.nogroup να μπορεί να γράφει στον κατάλογο /opt/myshare


/usr/local/samba/etc/samba/smb.conf


[global]
        workgroup = MYWORKGROUP
        server string = My Samba Server
        security = SHARE
        log file = /var/log/samba.log

[myshare]
        comment = My Share
        path = /opt/myshare
        force user = nobody
        force group = nogroup
        read only = No
        guest ok = Yes
        volume = myshare


top


init.d


Για προσωπική χρήση έχω γράψει ένα script για να εκκινώ τον samba daemon εύκολα:


$ cat /etc/init.d/smbd

#!/bin/sh
# Start / Stop Samba SMB/CIFS Daemon
# ebal 12.01.2008

server="Samba SMB/CIFS Daemon"
pidfile="/usr/local/samba/var/run/smbd.pid"
daemon="/usr/local/samba/sbin/smbd -D"

if [ -f $pidfile ]; then
        status=1
else
        status=0
fi

case "$1" in
'start')
        if [ 1 -eq $status ]; then
                $0 status
        else
                echo "Starting "$server "..."
                $daemon
                sleep 1
                $0 status
        fi
        ;;
'stop')
        if [ 1 -eq $status ]; then
                echo "Stoping "$server "..."
                kill -15 `cat $pidfile`
                sleep 1
                rm -f $pidfile
                $0 status
        else
                $0 status
        fi
        ;;
'status')
        if [ 1 -eq $status ]; then
                echo $server "is runnning with pid: `cat $pidfile`"
        else
                echo $server "is NOT running";
        fi
        echo
        ;;
'restart')
        $0 stop
        $0 start
        ;;
        *)
        echo -n "Usage: $0 {start|stop|restart|status)";
                echo "";
        exit 1
esac


top


Commands


Παρακάτω είναι οι πιο χρήσιμες και απλές εντολές που πρέπει κανείς να γνωρίζει.

smbstatus


smbstatus – report on current Samba connections


$ smbstatus
 
Global parameter guest account found in service section!
 
Samba version 3.0.28
PID Username      Group         Machine
-------------------------------------------------------------------
 
Service      pid machine       Connected at -------------------------------------------------------
 
No locked files

smbclient


smbclient – ftp-like client to access SMB/CIFS resources on servers


$ smbclient -U% -L localhost

Domain=[MYWORKGROUP] OS=[Unix] Server=[Samba 3.0.28]

        Sharename       Type      Comment
        ---------       ----      -------
        myshare           Disk
        IPC$            IPC       IPC Service (My Samba Server)

Domain=[MYWORKGROUP] OS=[Unix] Server=[Samba 3.0.28]

        Server               Comment
        ---------            -------
        MY.SERVER.GR     My Samba Server

        Workgroup            Master
        ---------            -------
        MYWORKGROUP

testparm


testparm – check an smb.conf configuration file for internal correctness


$ testparm samba.sample.config

[global]
        workgroup = MYWORKGROUP
        server string = My Samba Server
        interfaces = 10.10.10.1/255.255.255.0
        bind interfaces only = Yes
        security = SHARE
        log file = /var/log/samba.log
        hosts allow = 10.10.10.
        hosts deny = ALL

[myshare]
        comment = My Share
        path = /opt/myshare
        force user = nobody
        force group = nogroup
        read only = No
        guest ok = Yes
        volume = myshare

smbget


Πως "κατεβάζουμε" αρχεία από έναν διαδικτυακό κοινόχρηστο τόπο από κονσόλα:


smbget -u ebal -p'test' smb://192.168.2.2/C$/imortant/data.rar


top


hosts


Το παραπάνω παράδειγμα (αυτό με το testparm) μας παρέχει ασφάλεια σε επίπεδο δικτύου.
Μπορούμε να τροποποιήσουμε το αρχείο ρυθμίσεων ώστε να μας παρέχει ασφάλεια σε επίπεδο share.
Παρακάτω είναι δύο shares όπου στο πρώτο η πρόσβαση ορίζεται σε επίπεδο δικτύου (class c)
ενώ στο δεύτερο η πρόσβαση επιτρέπεται μόνο σε μία και μόνο Ip.


[global]
        workgroup = MyWorkgroup
        server string = My Samba Server
        interfaces = 10.10.10.1/255.255.255.0
        bind interfaces only = Yes security = SHARE
        log file = /var/log/samba.log
 
[myshare]
        comment = My Share
        path = /opt/myshare
        force user = nobody
        force group = nogroup
        read only = No guest ok = Yes hosts allow = 10.10.10.
        hosts deny = ALL volume = myshare
 
[myshare]
        comment = My Share
        path = /opt/myshare
        force user = nobody
        force group = nogroup
        read only = No guest ok = Yes hosts allow = 10.10.10.2
        hosts deny = ALL volume = myshare

top


Πως βάζουμε αυθεντικοποίηση


Υπάρχουν αρκετοί τρόποι για να προσθέσουμε αυθεντικοποίηση στους κοινόχρηστες φακέλους μας.
Ο πιο εύκολος τρόπος είναι η δημιουργία ενός αρχείου passwd ειδικά το οποίο θα παίζει το samba.


Έστω λοιπόν το εξής smb.conf


[global]
        log file = /usr/local/samba/var/samba.log
        printcap name = /dev/null
        smb passwd file = /usr/local/samba/lib/smbpasswd
[storage]
        path = /storage


ως διαχειριστές:


# smbpasswd -a test
New SMB password:
Retype new SMB password:

Added user test.

# cat /opt/samba-3.2.5/lib/smbpasswd
test:1001:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:0CB6948805F797BF2A82807973B89537:[U          ]:LCT-493EF7DB:


ΣΗΜΕΙΩΣΗ: Πρέπει να υπάρχει ο χρήστης test στο σύστημά μας


Για να το προσαρτήσουμε τον κοινόχρηστο κατάλογο στο σύστημά μας χρειάζεται να κάνουμε το εξής:


# mkdir -pv /media/storage
# smbmount //192.168.1.1/storage /media/storage/ -o user=test,pass='test'


top


samba4


[global]
        server string = Samba Server
        log file = /var/log/samba/%m.log
        max log size = 50
        dns proxy = No
        idmap config * : backend = tdb 

        # Global security
        map to guest = Bad User
        security = user
        public = Yes 
[data]
        path = /mnt/data/
        writable = Yes 
        read only = No


top



samba-3.6.9


# ebal, Sat, 15 Feb 2014 21:24:45 +0200

[global]
        workgroup = MYWORKGROUP
        server string = Samba Server

        max log size = 50
        log file = /var/log/samba/%m.log

        printcap name = /dev/null
        idmap config * : backend = tdb
        dns_proxy = no

        security = user
        map to guest = Bad User
        guest account = myuser

[myshare]
        comment = myshare
        path = /backup/myshare
        force user = myuser
        force group = mygroup
        read only = No
        guest ok = Yes
        public = Yes
        only guest = Yes
        writable = Yes


top