Crmgo Blog

Samba manual

Samba manual

Installing Samba Samba 3.0, unlike earlier versions of Samba, has the ability to operate in Windows networks running in Active Directory mode (or Windows 2000 native mode). If this functionality is required, you should install the samba3-3.0 package instead of samba-2.2. Active Directory…

Samba manual
Installing Samba

Unlike earlier versions of Samba, Samba 3.0 can operate in Windows networks running in Active Directory mode (or Windows 2000 native mode). If this functionality is required, you should install the samba3-3.0 package instead of samba-2.2.

Active Directory uses a different domain, computer, and user naming scheme based on DNS. For example, if there is a network named my.firm.com with computers host1.my.firm.com, host2.my.firm.com, and host3.my.firm.com, then the Active Directory domain will be named my.firm.com, and Active Directory users will have names in the format user@my.firm.com.

Configuration

/etc/krb5.conf must contain at least the following lines:

[realms]

MY.FIRM.COM = {
kdc = your.kerberos.server
}

where MY.FIRM.COM is the domain name (or "realm" in Kerberos terminology; it must be specified in uppercase), and your.kerberos.server is the name or IP address of the KDC (Kerberos Domain Controller), analogous to the PDC (Primary Domain Controller) in Windows NT domains — for example, server.my.firm.com or 192.168.117.11.

You can verify the correctness of the parameters by running the command (replace the username with the actual one — for example, administrator@MY.FIRM.COM):

# kinit username@REALM

and ensuring that the password was accepted by the server. REALM is always specified in uppercase.

You must also ensure that it is possible to resolve the KDC name from its IP address (so-called Reverse DNS lookup). The KDC name must either match the NetBIOS name of the computer (the machine name in the Windows network without the domain) or consist of the NetBIOS name and the domain name. If you cannot resolve the KDC name from the address, you will receive a "local error" when attempting to join the domain.

If your DNS does not support reverse lookups or the KDC is not registered in DNS, you can specify the IP address to name mapping in /etc/hosts.

Editing /etc/samba/smb.conf

To operate in Active Directory, smb.conf must contain the following parameters:

[global]

# Задает Kerberos realm, обычно совпадает с именем домена в
# верхнем регистре, например realm = MY.FIRM.COM
realm = <REALM>

# Это обычно часть реалма до первой точки, например
# workgroup = MY
workgroup = <WORKGROUP>

# Тип домена - Active Directory.
security = ADS

# В случае Active Directory пароли всегда шифруются.
encrypt passwords = true

# Обычно этот параметр указывать не обязательно, т.к. Samba сама
# определяет адрес KDC, если в сети есть WINS-сервер и он указан
# в smb.conf
ads server = <your.kerberos.server>

 

Registering the computer in the Active Directory domain

Ensure that Samba is not running. If it is, stop it:

# service smb stop; service winbind stop

 

To join the computer to the domain, run the command:

# net ads join -U administrator

where administrator is the domain user name that has the right to create new accounts.

If no error message was issued, the machine has been successfully registered in the domain — otherwise, check the correctness of the parameters in /etc/samba/smb.conf and /etc/krb5.conf. Ensure that the user specified after -U in net ads join has the necessary rights to create new accounts.

Now you can start the required services:

# service smb start; service winbind start

 

Verifying correct operation in Active Directory

To work with computers registered in Active Directory, you do not need to specify a username and password. Try running the command:

$ smbclient -k -L <имя компьютера в домене>

 

You should receive a list of available resources, and smbclient should not prompt for a username and password.

To verify that access to your machine's resources is possible from other domain machines, you can try running the same command:

$ smbclient -k -L <имя вашего компьютера в домене>

and obtain a list of available resources. You can also try accessing a resource on your machine from a Windows machine that is part of the domain. In any case, the username and password should not be requested.

Some features of working in Active Directory

Unlike Windows NT domains, authentication in Active Directory is performed not by username and password, but using Kerberos protocol tickets. Because of this, working with smbclient may initially seem unusual.

First, when invoking smbclient, you need to specify the -k option. Second, Kerberos tickets are issued for a specific period (usually for a day, but this depends on server settings). Therefore, they need to be periodically refreshed using the kinit command:

# kinit username@REALM

where username is your username in the Active Directory domain REALM.

So, if smbclient suddenly stops connecting to domain resources, try refreshing the ticket — most likely, that is the issue.

The article is taken from here
Deep within this structure, there is a directory named share to which access needs to be granted to different users (for example, user) via Samba. At the same time, the group cannot be changed, and the user does not belong to this group.

When creating directories in the share folder, they must have permissions 770, files within them 660, and also be accessible to user.

We use ACLs.

Run chmod g+s share ... so that created files and folders have the group project
Run setfacl -m u:user:rx for all directories up to share ... so that user can reach this directory
Run setfacl -m u:user:rwx for the share directory and all its subdirectories ... so that the user can create something in this directory
Run setfacl -m u:user:rw for all files in the share directory

In Samba, write

directory mask = 770
create mask = 660
inherit acls = yes
inherit permissions = yes # without this, the previous line does not work!!!
map acl inherit = yes
map archive = no
map system = no
map hidden = no

After that, try creating a folder and a file in the share directory via Samba as user.

You get
A folder with permissions 770 and owner user:project (everything as required)
and a file with permissions 670 and owner user:project

Note: This post may be AI-assisted and then human-edited. Editorial responsibility: Dmytro Lomaka, Kaltenkirchen.