r/linuxadmin • u/otariegarou • Nov 06 '25
Can I change homedir dynamically ?
Hi, My users are in ldap with an attribute homedir equal /home/$USER. I can’t modify ldap. But on my servers I don’t want create homedir for user. Can I dynamically modify homedir to equals /tmp without modify ldap ?
2
Upvotes
12
u/AdventurousSquash Nov 06 '25
You haven’t really provided any information other than the fact that there’s a LDAP you can’t modify so any answers you’ll get will be based on assumptions. With that said you can achieve this with SSSD for example. It can either (and this is the default) retrieve the home dir supplied by LDAP or override it.
See override_homedir here:
https://linux.die.net/man/5/sssd-ad
3
u/minimishka Nov 06 '25
SSSD with override_homedir = /tmp would be the best solution. Or via PAM exec
7
u/michaelpaoli Nov 06 '25
Using /tmp or directories under /tmp for user's home directories is probably in general a bad idea. If you really don't want to create user's home directories (and can even have 'em created upon use by PAM, or NFS automounted upon use), then probably best to not give 'em HOME directories at all, so, e.g. in LDAP, give a HOME directory location that either does not and will never exist, or is quite securely locked, e.g. root:root 755 and exactly nothing in it.
And no, if you're getting your data from LDAP, that's what you get. Though can change HOME in environment for a user after they're logged in, but that won't change the pwent data, so, depending how one inquires about HOME directory for the user, if you go that route, you may get inconsistent results, and that might be problematic.
So ... what exactly are you trying to achieve ... and why?
1
u/FarToe1 Nov 07 '25
What about a cd in a /etc/profile.d/ script?
It's run after a successful login so can set envs and run arbitrary commands.
1
u/roadit Nov 07 '25
You can make /home/$USER a symlink to wherever. Just don't make it a symlink to /tmp (where anyone can write, see the other replies).