In short:
Would like a way to do SSH key authentication via LDAP.
Problem:
We use LDAP (slapd) for directory services and we've recently moved to using our own AMI for building instances. The reason the AMI bit is important is that, ideally, we would like to be able to login with SSH via key authentication as soon as the instance is running and not have to wait for our somewhat slow configuration management tool to kickoff a script to add the correct keys to the instance.
The ideal scenario is that, when adding a user to LDAP we add their key as well and they'd be immediately be able to login.
Key authentication is a must because password-based login is both less secure and bothersome.
I've read this question which suggests there's a patch for OpenSSH called OpenSSH-lpk to do this but this is no longer needed with OpenSSH server >= 6.2
Added a sshd_config(5) option AuthorizedKeysCommand to support fetching authorized_keys from a command in addition to (or instead of) from the filesystem. The command is run under an account specified by an AuthorizedKeysCommandUser sshd_config(5) option
How can I configure OpenSSH and LDAP to implement this?
AuthorizedKeysCommandUser nobodyinstead of root. – TRS-80 Mar 27 '15 at 12:14ldapsearch -u -LLL -o ldif-wrap=no '(&(objectClass=posixAccount)(uid='"$1"'))' 'sshPublicKey' | sed -n 's/^[ \t]*sshPublicKey:[ \t]*\(.*\)/\1/p'– Chris L Jun 23 '15 at 20:45AuthorizedKeysCommandRunAsand notAuthorizedKeysCommandUser– mveroone Jun 16 '17 at 15:25awk '/^sshPublicKey/{$1=""; p=1} /^$/{p=0} {printf p?$0:""}'which is much cleaner IMO. – miken32 May 01 '18 at 21:25AuthorizedKeysCommand /script %uto pass the user to it with openssh 1:7.2p2-4ubuntu2.4. This option also doesn't exist before openssh 6.2 – jdf Jun 07 '19 at 19:43authlogin_nsswitch_use_ldapselinux knob. – drookie Oct 01 '20 at 11:16