Skip to main content
Overview

SMB Authentication with AD on Linux

5 min read

After days of configuration and research, I couldn’t find a single source that covered everything needed for this setup end to end. My job requires centralized SSSD across all Linux servers, so here’s what I got working on both RHEL 8 and OpenSUSE 15.6.

The stack: Samba for SMB/CIFS, SSSD for AD integration, Kerberos for authentication, and realmd for domain join.

What you need before starting: DNS resolving your domain controllers, NTP/Chrony running and synced, a domain admin account with join privileges, and the following info on hand — domain name (company.com), DC hostname (dc1.company.com).

Step 1: Package Installation

RHEL/CentOS/Rocky Linux

Terminal window
sudo dnf install -y realmd sssd oddjob oddjob-mkhomedir adcli \
samba-common-tools krb5-workstation chrony samba samba-client \
cifs-utils policycoreutils-python-utils
sudo systemctl enable --now chronyd
sudo systemctl enable --now sssd

Ubuntu/Debian

Terminal window
sudo apt update
sudo apt install -y realmd sssd sssd-tools libnss-sss libpam-sss \
adcli samba-common-bin krb5-user chrony samba samba-client \
cifs-utils policycoreutils-python-utils
sudo systemctl enable --now chrony
sudo systemctl enable --now sssd

Step 2: DNS and Time

/etc/resolv.conf

nameserver 192.168.1.10
nameserver 192.168.1.11
search company.com
domain company.com

Verify:

Terminal window
dig company.com
dig _ldap._tcp.company.com SRV

/etc/chrony.conf

server dc1.company.com iburst prefer
server dc2.company.com iburst
Terminal window
sudo systemctl restart chronyd
chrony sources -v
timedatectl status

Step 3: Kerberos Configuration

/etc/krb5.conf

[libdefaults]
default_realm = COMPANY.COM
dns_lookup_kdc = true
dns_lookup_realm = false
rdns = false
ticket_lifetime = 24h
renew_lifetime = 7d
forwardable = true
udp_preference_limit = 0
[realms]
COMPANY.COM = {
kdc = dc1.company.com
admin_server = dc1.company.com
default_domain = company.com
}
[domain_realm]
.company.com = COMPANY.COM
company.com = COMPANY.COM
[logging]
kdc = FILE:/var/log/krb5/krb5kdc.log
admin_server = FILE:/var/log/krb5/kadmind.log
default = SYSLOG:NOTICE:DAEMON

Test it:

Terminal window
kinit administrator@COMPANY.COM
klist
kdestroy

Step 4: Domain Join

Terminal window
sudo realm discover company.com
sudo realm join company.com -U administrator \
--client-software=sssd \
--membership-software=samba
sudo realm list
net ads testjoin

Step 5: SSSD Configuration

/etc/sssd/sssd.conf

[sssd]
enable_files_domain = true
domains = company.com
config_file_version = 2
services = nss, pam
[domain/local]
id_provider = files
[domain/company.com]
ad_domain = company.com
krb5_realm = COMPANY.COM
realmd_tags = manages-system joined-with-samba
cache_credentials = True
id_provider = ad
ad_update_samba_machine_account_password = True
full_name_format = %3$s\%1$s
use_fully_qualified_names = False
fallback_homedir = /home/%u
default_shell = /bin/bash
# Disable for consistent UIDs across servers
ldap_id_mapping = False
krb5_store_password_if_offline = True
access_provider = simple
simple_allow_groups = linuxadmins@company.com, itstaff@company.com
simple_allow_users = testuser@company.com
enumerate = False
cache_first = True
Terminal window
sudo chmod 600 /etc/sssd/sssd.conf
sudo systemctl restart sssd
sudo systemctl enable sssd

Step 6: NSS Configuration

/etc/nsswitch.conf

passwd: files sss winbind
group: files sss winbind
shadow: files sss
netgroup: sss files

Step 7: Samba Configuration

/etc/samba/smb.conf

[global]
realm = COMPANY.COM
workgroup = COMPANY
security = ads
kerberos method = secrets and keytab
dedicated keytab file = /etc/krb5.keytab
log file = /var/log/samba/log.%m
log level = 2
vfs objects = acl_xattr
map acl inherit = yes
store dos attributes = yes
template homedir = /home/%U
template shell = /bin/bash
idmap config * : backend = tdb
idmap config * : range = 10000-199999
idmap config COMPANY : range = 200000-2147483647
idmap config COMPANY : backend = sss
client signing = mandatory
server signing = mandatory
socket options = TCP_NODELAY IPTOS_LOWDELAY
[shared]
path = /srv/shared
read only = no
browsable = yes
valid users = @linuxadmins@company.com, @itstaff@company.com
force group = linuxadmins
create mask = 0664
directory mask = 0775
[data]
path = /srv/data
read only = no
browsable = yes
valid users = @dataaccess@company.com
force group = dataaccess
create mask = 0660
directory mask = 0770
[homes]
comment = Home Directories
browsable = no
read only = no
create mask = 0700
directory mask = 0700

Create share directories

Terminal window
sudo mkdir -p /srv/shared /srv/data
sudo chgrp linuxadmins /srv/shared
sudo chmod 775 /srv/shared
sudo chgrp dataaccess /srv/data
sudo chmod 770 /srv/data
# SELinux (RHEL/CentOS)
sudo setsebool -P samba_export_all_ro=1 samba_export_all_rw=1
sudo semanage fcontext -a -t samba_share_t "/srv/shared(/.*)?"
sudo semanage fcontext -a -t samba_share_t "/srv/data(/.*)?"
sudo restorecon -R /srv/shared /srv/data

Step 8: Join Samba to Domain

Terminal window
sudo net ads join -U administrator
sudo net ads testjoin
# Should return: Join is OK
# Verify user/group lookup
getent passwd testuser@company.com
id testuser@company.com
getent group linuxadmins@company.com

Step 9: Start Services and Test

Terminal window
sudo systemctl enable --now smb winbind
sudo systemctl status smb winbind
# List shares
sudo smbclient -L localhost -U testuser@company.com
# Test share access
sudo smbclient //localhost/shared -U testuser@company.com

From a Windows client: \\linux-server\shared

Step 10: Troubleshooting

Cache

Terminal window
sudo sss_cache -E
sudo systemctl restart sssd
sudo net cache flush
# If TDB corruption suspected
sudo systemctl stop smb winbind
sudo rm -f /var/lib/samba/*.tdb
sudo systemctl start winbind smb

Logs

Terminal window
sudo tail -f /var/log/sssd/sssd_company.com.log
sudo tail -f /var/log/samba/log.smbd

For deeper SSSD debugging, add debug_level = 9 in the [domain/company.com] section and restart sssd.

AD Connectivity and Auth

Terminal window
sudo net ads info
sudo net ads lookup testuser
sudo net ads group info "linuxadmins"
klist -k /etc/krb5.keytab
# Winbind checks
sudo wbinfo -t # trust secret
sudo wbinfo -u # list users
sudo wbinfo -g # list groups
# Active connections
sudo smbstatus

Common Errors

NT_STATUS_ACCESS_DENIED:

Terminal window
id username@company.com
sudo testparm -s
ls -Z /srv/shared

Users not resolving:

Terminal window
sudo sss_cache -E
sudo systemctl restart sssd winbind
getent passwd username@company.com

Authentication failures:

Terminal window
klist
kinit username@COMPANY.COM
chrony sources -v
net ads testjoin

Firewall and SELinux

Terminal window
sudo firewall-cmd --permanent --add-service=samba
sudo firewall-cmd --permanent --add-port=445/tcp
sudo firewall-cmd --permanent --add-port=139/tcp
sudo firewall-cmd --reload
# SELinux booleans (RHEL/CentOS)
sudo setsebool -P samba_domain_controller=on
sudo setsebool -P use_samba_home_dirs=on
sudo setsebool -P samba_enable_home_dirs=on

Maintenance Script

Terminal window
sudo nano /usr/local/bin/samba-maintenance.sh
#!/bin/bash
net ads changetrustpw
sss_cache -E
tdbbackup /var/lib/samba/*.tdb
net ads testjoin
echo "Maintenance completed: $(date)"
Terminal window
sudo chmod +x /usr/local/bin/samba-maintenance.sh
# Weekly cron
echo "0 2 * * 0 /usr/local/bin/samba-maintenance.sh >> /var/log/samba-maintenance.log 2>&1" | sudo crontab -

Share this post

Loading comments...