Samba-integrering mot Active Directory

Få åtkomst till en Samba-delning

Another use for Samba is to integrate into an existing Windows network. Once part of an Active Directory (AD) domain, Samba can provide file and print services to AD users.

The simplest way to join an AD domain is to use Likewise-open. For detailed instructions, see the section called “Likewise Open”.

Så snart du anslutit till domänen, skriv följande kommando i terminalprompten:

sudo apt-get install samba smbfs smbclient

Since the likewise-open and samba packages use separate secrets.tdb files, a symlink must be created in /var/lib/samba:

sudo mv /var/lib/samba/secrets.tdb /var/lib/samba/secrets.tdb.orig
sudo ln -s /etc/samba/secrets.tdb /var/lib/samba

Nästa steg, redigera /etc/samba/smb.conf och ändra:

workgroup = EXAMPLE
...
security = ads
realm = EXAMPLE.COM
...
idmap backend = lwopen
idmap uid = 50-9999999999
idmap gid = 50-9999999999

Starta om samba för att de nya inställningarna skall få effekt:

sudo /etc/init.d/samba restart

It should now be possible to access any Samba shares from a Windows client. However, be sure to give the appropriate AD users or groups access to the share directory. See the section called “Säkra en Samba fil- och skrivarserver” for more details.

Få åtkomst till en Windows-utdelning

Now that the Samba server is part of the Active Directory domain, any Windows server shares can be accessed:

  • To mount a Windows file share, enter the following in a terminal prompt:

    mount.cifs //fs01.example.com/share mount_point
    

    It is also possible to access shares on computers not part of an AD domain, but a username and password must be provided.

  • To mount the share during boot, place an entry in /etc/fstab, for example:

    //192.168.0.5/share /mnt/windows cifs auto,username=steve,password=secret,rw 0        0
    
  • Ett annat sätt att kopiera filer från en Windows-server är att använda hjälpprogrammet smbclient. För att lista filerna i en Windows-utdelning:

    smbclient //fs01.example.com/share -k -c "ls"
    
  • För att kopiera en fil till utdelningen, skriv:

    smbclient //fs01.example.com/share -k -c "get file.txt"
    

    Detta kommer att kopiera file.txt till den nuvarande katalogen.

  • Och för att kopiera en fil till utdelningen:

    smbclient //fs01.example.com/share -k -c "put /etc/hosts hosts"
    

    Detta kommer kopiera /etc/hosts till //fs01.example.com/share/hosts.

  • The -c option used above allows execution of the smbclient command all at once. This is useful for scripting and minor file operations. To enter the smb: \> prompt, an FTP-like prompt where normal file and directory commands can be executed, simply run the following in Konsole:

    smbclient //fs01.example.com/share -k
    

Note

Replace all instances of fs01.example.com/share, //192.168.0.5/share, username=steve,password=secret, and file.txt with the proper server IP, hostname, share name, file name, and an actual username and password with rights to the share.

Resurser

För fler alternativ till smbclient se man-sidorna: man smbclient, också tillgängligt som direkthjälp.

mount.cifsman-sida är också användbar för ytterligare detaljered information.