[python-ldap] Read/Change public ssh key with ldap-python
Raphaël Barrois
raphael.barrois at m4x.org
Mon Aug 18 20:15:15 CEST 2014
On Mon, 18 Aug 2014 09:44:10 -0700
John Theodore <JohnTheodore42 at gmail.com> wrote:
> I'm trying to make a simple web app that can manage/change my public
> ssh keys on ldap using python-ldap and django. I'm trying to
> understand the ldap library better. I know I can query the ldap box
> and get a list of attributes (including public ssh keys) by doing
> this command:
>
> l=ldap.initialize("ldap://myldaphost.mydomain.com")
> l.simple_bind_s("CN=ldapuser,CN=Users,DC=mydomain, DC=com","secret")
> r = l.search_s(
> "CN=ANYCOMPUTER,CN=Computers,DC=mydomain,DC=co m",
> ldap.SCOPE_SUBTREE, # this is the default of ldapsearch
> "(objectClass=*)"
> )
>
> .
> What I'm trying to figure out, is how can I delete or update an ssh
> key for a specific account? The command I would be doing on
> ldapmodify is this:
>
> ldapmodify -h localhost -D
> "uid=user,ou=People,dc=mgmt,dc=symcpe,dc=net" -w $passwrd
> -f /tmp/usertomod.ldif.
>
> How can I duplicate this command in python-ldap?
Hi John,
This would be done with modify() and delete():
http://www.python-ldap.org/doc/html/ldap.html#ldap.LDAPObject.modify
http://www.python-ldap.org/doc/html/ldap.html#ldap.LDAPObject.delete
If you're using Django, you might also be interested in django-ldapdb (https://github.com/jlaine/django-ldapdb), which provides Django-like models backed on a LDAP database, i.e with a higher level API.
--
Raphaël
More information about the python-ldap
mailing list