r/AlpineLinux • u/Arctic_Turtle • Dec 06 '25
HOWTO: Alpine Linux with KDE and login with LDAP users
So I installed Alpine on a server and loved it, so I decided to try it as a daily driver on my laptop. Not easy, it's been a bit of a trip, mostly because I am running OpenLDAP on the server and getting it to work with KDE is a real challenge. The basic problem is that Alpine uses musl and that is more or less hard-coded to look at local files for login etc (if you add files in nsswitch.conf you get errors and crashes, because the necessary files for checking files for permissions are missing - because it's built into musl). Anyway, I had to do and redo this a number of times after locking myself out of the laptop (no root access, no login at all, etc) when playing around with pam. So in the end I made a script that I can just run and if things break start over with a fresh install again. So I figured if someone else is playing around with this, perhaps you will benefit from having a look at my script. If no one is interested then this is just another backup for me. So here it is:
(oh yeah, I'm Swedish so some comments in Swedish, you can figure it out I'm sure)
#!/bin/ash# -----------------------------------------------------------------------------# ALPINE LINUX LDAP KLIENT-SETUP# Denna fil ska köras som root EFTER setup-alpine (välj sys, och skapa en lokal användare)# -----------------------------------------------------------------------------
echo "--- 1. KONFIGURERAR EDITOR ---"apk add nano nano-syntax sed -i 's|^#set autoindent|set autoindent|g' /etc/nanorcsed -i 's|^#set linenumbers|set linenumbers|g' /etc/nanorcsed -i 's|^#include /usr/share/nano/*.nanorc|include /usr/share/nano/*.nanorc|g' /etc/nanorcln -s /usr/bin/nano /bin/vi ln -s /usr/bin/nano /bin/vim
echo "--- 2. KONFIGURERAR SHELL ---"scp <username>@<server>:/home/<username>/profile.d/* /etc/profile.d/apk add doas doas-sudo-shim bashecho "permit persist :wheel" > /etc/doas.d/doas.confchmod 0600 /etc/doas.d/doas.confadduser <username> wheelchsh -s /bin/bash rootchsh -s /bin/bash <username>echo 'PATH="$PATH:/sbin:/usr/sbin"' >> /etc/profile.d/fixpath.shecho 'PATH="$PATH:/sbin:/usr/sbin"' >> /etc/bash/bashrc
echo "--- 3. KONFIGURERAR SKRIVBORDSMILJÖ ---"echo "Välj plasma för KDE"setup-desktop# Behövs för kwalletapk add gnupg# Behövs för wifirc-service networkmanager startrc-update add networkmanager default
echo "--- 4. KONFIGURERAR LDAP ---"apk add openldap-clients nss-pam-ldapd musl-nscd util-linux-login shadow
# nano /etc/pam.d/su-lcat <<EOF > /etc/pam.d/su-l# basic PAM configuration for Alpine.auth sufficient pam_rootok.so#auth include base-auth#account include base-account#password include base-password#session include base-sessionEOFecho "auth include system-auth" >> /etc/pam.d/su-lecho "account include system-auth" >> /etc/pam.d/su-lecho "password include system-auth" >> /etc/pam.d/su-lecho "session include system-auth" >> /etc/pam.d/su-l# Sen kopierar vi filen eftersom det kan bli fel om su inte finns, bara su-l.cp /etc/pam.d/su-l /etc/pam.d/su# OBS att musl alltid läser files, därför kraschar allt om man försöker lägga# till files i nsswitch.conf! Däremot verkar det behövas för shadow?#nano /etc/nsswitch.confecho "passwd: ldap" >> /etc/nsswitch.confecho "group: ldap" >> /etc/nsswitch.confecho "shadow: files ldap" >> /etc/nsswitch.conf
#nano /etc/nslcd.confsed -i 's|^#uri ldap://127.0.0.1/|uri ldaps://<server.com>/|g' /etc/nslcd.confsed -i 's|^#base dc=example,dc=com|base dc=domain,dc=se|g' /etc/nslcd.conf# ev om binddn behövs#sed -i 's|^#binddn cn=proxyuser,dc=example,dc=com|binddn cn=admin,dc=domain,dc=se|g' /etc/nslcd.conf#sed -i 's|^#bindpw secret|bindpw <pwd>|g' /etc/nslcd.confsed -i 's|^#ssl start_tls|ssl on|g' /etc/nslcd.confsed -i 's|^#tls_reqcert never|tls_reqcert allow|g' /etc/nslcd.confecho "validnames /.*/" >> /etc/nslcd.conf
#nano /etc/pam.d/system-authcat <<EOF > /etc/pam.d/system-auth# PAM-ordning: LDAP före UNIX, och mkhomedir sist.
auth required pam_env.soauth sufficient pam_ldap.so use_first_passauth sufficient pam_unix.so nullok try_first_passauth required pam_deny.so
account sufficient pam_ldap.so ignore_authinfo_unavail ignore_unknown_useraccount required pam_unix.so
password required pam_unix.so nullok sha512 shadow try_first_pass
session required pam_limits.sosession required pam_env.sosession optional pam_unix.sosession optional pam_ldap.sosession optional pam_mkhomedir.so skel=/etc/skel umask=0077EOF
### Sist men inte minst:rc-update add nslcd defaultrc-update add nscd defaultrc-service nslcd startrc-service nscd start
# Så här långt funkar det att logga in med LDAP i terminal, men vi # måste såklart också få sddm att lista användare.
# Här finns det nån slags magi som jag inte lyckats lista ut än...
cat <<EOF > /etc/pam.d/sddmsudo cat /etc/pam.d/sddm#%PAM-1.0
auth include base-auth-auth optional pam_gnome_keyring.so-auth optional pam_kwallet5.so
account include base-account
password include base-password-password optional pam_gnome_keyring.so use_authtok
session optional pam_keyinit.so force revokesession include base-session-session optional pam_gnome_keyring.so auto_start-session optional pam_kwallet5.so auto_startauth include system-authaccount include system-authpassword include system-authsession include system-authEOF
#sudo nano /etc/sddm.confcat <<EOF > /etc/sddm.conf[Theme]Current=breezeCursorTheme=breeze_cursors
[Users]# Se till att MinimumUid är 1000 (standard), vilket täcker LDAP-användareMinimumUid=1000# Säkerställ att vi inte gömmer någon standardanvändareHiddenUsers=# Standardinställningen för systemgrupper (t.ex. bin, daemon)HiddenShells=/usr/sbin/nologin,/bin/false# Gömmer användare som har en UID högre än detta. Vi sätter det högt.MaximumUid=60000EOF
echo "testa med: getent passwd <username>"echo "testa sen: id <username>"echo "testa sen: su - <username>"
echo "reboot"
As of now, this only works to let you in sddm click on "other user" and manually type in an LDAP user name with password. The list of users in sddm only brings up the users that have been created locally on the laptop (not even bringing up LDAP users after they have been logged in and there are KDE settings and home dir etc). So it's not perfect. But it does work.
If anyone has some suggestions for how this could be improved, I'm glad to hear it. If someone has the magic formula for listing LDAP users on login, that would be swell.
As a side note, I never actually ran this as a script, more like a memory pad, because after I decided to make the script I finally was able to make it work without having to reinstall again.
