• Stars
    star
    217
  • Rank 182,446 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created over 10 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Utility to manage SSH public keys stored in LDAP.

OpenSSH / LDAP public keys

Build Status Code Climate version

This project provides an utility to manage SSH public keys stored in LDAP and also a script for OpenSSH server to load authorized keys from LDAP.

Why?

When you have dozen of servers it becomes difficult to manage your authorized keys. You have to copy all your public keys to ~/.ssh/authorized_keys on every server you want to login to. And what if you someday change your keys?

It’s a good practice to use some kind of a centralized user management, usually an LDAP server. There you have user’s login, uid, e-mail, … and password. What if we could also store public SSH keys on LDAP server? With this utility it’s easy as pie.

Alternatives

If you need just a lightweight utility for OpenSSH server to load authorized keys from LDAP, then you can use ssh-getkey-ldap written in Lua or this one written in POSIX shell (but it requires ldapsearch utility and may not work well on some systems).

Requirements

You can install both Python modules from PyPI. python-ldap requires additional system dependencies – OpenLDAP. Refer to Stack Overflow for distribution-specific information.

Installation

PyPI:

pip install ssh-ldap-pubkey

Alpine Linux

apk add ssh-ldap-pubkey

Note: The package is currently in the (official) community repository; make sure that you have community in /etc/apk/repositories.

Usage

List SSH public keys stored in LDAP for the current user:

ssh-ldap-pubkey list

List SSH public keys stored in LDAP for the specified user:

ssh-ldap-pubkey list -u flynn

Add the specified SSH public key for the current user to LDAP:

ssh-ldap-pubkey add ~/.ssh/id_rsa.pub

Remove SSH public key(s) of the current user that matches the specified pattern:

ssh-ldap-pubkey del flynn@grid

Specify LDAP URI and base DN on command line instead of configuration file:

ssh-ldap-pubkey list -b ou=People,dc=encom,dc=com -H ldaps://encom.com -u flynn

As the LDAP manager, add SSH public key to LDAP for the specified user:

ssh-ldap-pubkey add -D cn=Manager,dc=encom,dc=com -u flynn ~/.ssh/id_rsa.pub

Show help for other options:

ssh-ldap-pubkey --help

Configuration

Configuration is read from /etc/ldap.conf — file used by LDAP nameservice switch library and the LDAP PAM module. An example file is included in etc/ldap.conf. The following subset of parameters are used:

  • uri ... URI(s) of the LDAP server(s) to connect to, separated by a space. The URI scheme may be ldap, or ldaps. Default is ldap://localhost.
  • nss_base_passwd ... distinguished name (DN) of the search base.
  • base ... distinguished name (DN) of the search base. Used when nss_base_passwd is not set.
  • scope ... search scope; sub, one, or base (default is sub).
  • referrals ... should client automatically follow referrals returned by LDAP servers (default is on)?
  • pam_filter ... filter to use when searching for the user’s entry, additional to the login attribute value assertion (pam_login_attribute=<login>). Default is objectclass=posixAccount.
  • pam_login_attribute ... the user ID attribute (default is uid).
  • ldap_version ... LDAP version to use (default is 3).
  • sasl ... enable SASL and specify mechanism to use (currently only GSSAPI is supported).
  • binddn ... distinguished name (DN) to bind when reading the user’s entry (default is to bind anonymously).
  • bindpw ... credentials to bind with when reading the user’s entry (default is none).
  • ssl ... LDAP SSL/TLS method; off, on, or start_tls. If you use LDAP over SSL (i.e. URI ldaps://), leave this empty.
  • timelimit ... search time limit in seconds (default is 10).
  • bind_timelimit ... bind/connect time limit in seconds (default is 10). If multiple URIs are specified in uri, then the next one is tried after this timeout.
  • tls_cacertdir ... path of the directory with CA certificates for LDAP server certificate verification.
  • pubkey_class ... objectClass that should be added/removed to/from the user’s entry when adding/removing first/last public key and the pubkey_attr is mandatory for this class. This is needed for the original openssh-lpk.schema (not for the one in this repository). Default is ldapPublicKey.
  • pubkey_attr ... name of LDAP attribute used for SSH public keys (default is sshPublicKey).

The only required parameter is nss_base_passwd or base, others have sensitive defaults. You might want to define uri parameter as well. These parameters can be also defined/overriden with --bind and --uri options on command line.

For more information about these parameters refer to ldap.conf man page.

Set up OpenSSH server

To configure OpenSSH server to fetch users’ authorized keys from LDAP server:

  1. Make sure that you have installed ssh-ldap-pubkey and ssh-ldap-pubkey-wrapper in /usr/bin with owner root and mode 0755.

  2. Add these two lines to /etc/ssh/sshd_config:

    AuthorizedKeysCommand /usr/bin/ssh-ldap-pubkey-wrapper
    AuthorizedKeysCommandUser nobody
    
  3. Restart sshd and check log file if there’s no problem.

Note: This method is supported by OpenSSH since version 6.2-p1 (or 5.3 onRedHat). If you have an older version and can’t upgrade, for whatever weird reason, use openssh-lpk patch instead.

Set up LDAP server

Just add the openssh-lpk.schema to your LDAP server, or add an attribute named sshPublicKey to any existing schema which is already defined in people entries. That’s all.

Note: Presumably, you’ve already set up your LDAP server for centralized unix users management, i.e. you have the NIS schema and users in LDAP.

License

This project is licensed under MIT license.

More Repositories

1

rsql-parser

Parser for RSQL / FIQL – query language for RESTful APIs
Java
685
star
2

spring-rest-exception-handler

A convenient Spring MVC exception handler for RESTful APIs.
Java
354
star
3

maven-badges

Badge for Maven Central
Ruby
240
star
4

ldap-passwd-webui

Very simple web interface for changing password stored in LDAP or Active Directory (Samba 4 AD).
Python
198
star
5

luapak

Easily build a standalone executable for any Lua program
Lua
175
star
6

esh

Simple templating engine based on shell.
Shell
172
star
7

ngx-oauth

OAuth 2.0 proxy for nginx written in Lua.
Lua
156
star
8

validator-collection

The easiest way to validate collections of basic types using Bean Validation.
Java
120
star
9

smlar

PostgreSQL extension for an effective similarity search || mirror of git://sigaev.ru/smlar.git || see https://www.pgcon.org/2012/schedule/track/Hacking/443.en.html
C
110
star
10

zsh-shift-select

Select text in Zsh command line using Shift, as in many text editors and GUI programs
Shell
107
star
11

setup-alpine

Easily use Alpine Linux on GitHub Actions, with support for QEMU user emulator
Shell
105
star
12

tty-copy

Copy content to system clipboard via TTY and terminal using ANSI OSC52 sequence
C
94
star
13

validator-spring

Bean Validator utilizing Spring Expression Language (SpEL)
Java
84
star
14

asciidoctor-html5s

Semantic HTML5 converter (backend) for Asciidoctor
HTML
79
star
15

luasrcdiet

Compresses Lua source code by removing unnecessary characters (updated fork of http://luasrcdiet.luaforge.net/)
Lua
64
star
16

apk-autoupdate

Automatic updates for Alpine Linux and other systems using apk-tools
Shell
45
star
17

embedmongo-spring

Spring Factory Bean for “Embedded” MongoDB
Java
44
star
18

nginx-binaries

Nginx and njs binaries for Linux (x86_64, aarch64, ppc64le), macOS and Windows. Linux binaries are static so works on every Linux.
TypeScript
44
star
19

otf2bdf

OpenType to BDF Converter (unofficial mirror)
C
42
star
20

njs-typescript-starter

A starting template for developing njs (NGINX JavaScript) scripts for NGINX server in TypeScript.
JavaScript
42
star
21

apcupsd-snmp

Apcupsd module for Net-SNMP
Perl
41
star
22

doas-sudo-shim

sudo shim for doas
Shell
39
star
23

qemu-openrc

OpenRC init script for QEMU/KVM (for Gentoo and Alpine Linux)
Shell
30
star
24

rake-jekyll

Rake tasks for Jekyll as a gem.
Ruby
30
star
25

akms

Alpine Kernel Module Support – aka DKMS for Alpine Linux
Shell
29
star
26

corefines

💎 A collection of refinements for Ruby core classes with a compatibility mode for older Rubies and a convenient syntactic sugar.
Ruby
26
star
27

user-aports

My Alpine Linux aports that are not in official repository yet or don’t adhere to Alpine polices (bundles)
Shell
26
star
28

ipynb2html

Convert Jupyter (IPython) Notebooks to static HTML
TypeScript
26
star
29

sh-parser

Parser of POSIX Shell Command Language
Lua
25
star
30

zzz

A simple program to suspend or hibernate your computer 💤
C
22
star
31

nginx-testing

Support for integration/acceptance testing of nginx configuration in TypeScript/JavaScript.
TypeScript
21
star
32

asciidoctor-highlight.js

Asciidoctor.js extension for highlighting code in build time using Highlight.js
JavaScript
21
star
33

opensmtpd-filter-rewrite-from

OpenSMTPD 6.6+ filter for rewriting From address
Awk
18
star
34

asciidoctor-rouge

Rouge code highlighter support for Asciidoctor (OBSOLETE)
Ruby
18
star
35

efi-mkuki

EFI Unified Kernel Image Maker
Shell
17
star
36

asciidoctor-katex

Asciidoctor extension for converting latexmath using KaTeX at build time
Ruby
17
star
37

babel-preset-njs

A Babel preset for njs - NGINX JavaScript
JavaScript
17
star
38

ssh-getkey-gitlab

A simple script to be used as AuthorizedKeysCommand in OpenSSH server to look up user’s public keys in GitLab or GitHub.
Shell
17
star
39

unidecode

Transliteration from Unicode to US-ASCII and ISO 8859-2.
Java
14
star
40

alpine-zsh-config

A sensible system-wide Zsh configuration for Alpine Linux
Shell
14
star
41

haste-client

CLI client for haste-server (hastebin.com) written in Python
Python
13
star
42

ts-transformer-inline-file

A TypeScript custom transformer for inlining files
TypeScript
12
star
43

argp

Rust derive-based argument parsing optimized for code size and flexibility
Rust
12
star
44

stunnel-static

stunnel built as a fully static binary
Shell
11
star
45

swaylockd

A dumb launcher to spawn swaylock and ensure it runs no matter what
C
11
star
46

ssh-getkey-ldap

A simple script to be used as AuthorizedKeysCommand in OpenSSH server to look up user’s public keys in LDAP.
Lua
11
star
47

ansible-gentoo-roles

A curated list of Ansible roles for Gentoo Linux.
10
star
48

asciidoctor-include-ext

Asciidoctor’s standard include processor reimplemented as an extension
Ruby
9
star
49

muacme

A convenient wrapper for the ACMEv2 client uacme
Shell
8
star
50

rsql-hibernate

This project is outdated. Use https://github.com/tennaito/rsql-jpa instead.
Java
8
star
51

github-pr-closer

GitHub webhook handler for closing pull requests that have been merged using rebase etc.
Python
8
star
52

dokuwiki2adoc

Converter from DokuWiki to AsciiDoc formatted text files.
Shell
8
star
53

sloci-image

Simple script for creating single-layer OCI images.
Shell
8
star
54

brieflz.lua

Lua binding for BriefLZ compression library
C
7
star
55

asciidoctor-interdoc-reftext

Asciidoctor extension providing implicit (automatic) reference text (label) for inter-document cross references
Ruby
7
star
56

spring-boot-openrc

OpenRC init script for Java applications based on Spring Boot
Shell
7
star
57

efi-mkkeys

Script to easily generate self-signed UEFI keys for Secure Boot
Shell
7
star
58

rsub-client

Open and edit files from a remote machine in your local Sublime Text or TextMate 2.
Python
6
star
59

git-metafile

Store and restore files metadata (mode, owner, group) in a git repository
Rust
6
star
60

unboundid-spring

Spring Factory Beans for UnboundID LDAP SDK
Java
6
star
61

alpkit

Rust library and CLI tool for reading Alpine Linux’s apk package format and APKBUILD
Rust
5
star
62

emscripten-travis-example

How to easily use Emscripten on Travis CI or any other CI
C
5
star
63

cesnet-tcs-cli

CLI client utility for CESNET TCS API
Shell
5
star
64

slava-ukrajine

Слава Україні! / Sláva Ukrajině! – grafika
4
star
65

asciidoctor-templates-compiler

Compile templates-based Asciidoctor converter (backend) into a single Ruby file
Ruby
4
star
66

spring-http-client-cache

A very simple HTTP cache for the Spring’s RestTemplate.
4
star
67

one-context

OpenNebula contextualization scripts for Alpine Linux and Gentoo
Shell
4
star
68

uidmapshift

Shift UIDs/GIDs of directory entries recursively by some offset
Lua
4
star
69

yaml-env-tag

Custom YAML tag for referring environment variables in YAML documents
Ruby
3
star
70

mtype

An enhanced Lua type() function that looks for __type metafield
Lua
3
star
71

CSFD-parser

Parser for movie pages and search on CSFD.cz
Python
3
star
72

commons-hibernate

My collection of reusable Java classes for Hibernate.
Java
3
star
73

virt-init

Provisioning scripts for Alpine Linux VMs
Shell
3
star
74

keycloak-json-schema

JSON schemas for Keycloak realm configuration
JavaScript
3
star
75

redmine_agile

Archive of redmine_agile plugin downloaded from https://www.redmineup.com/pages/plugins/agile
Ruby
3
star
76

apk-deploy-tool

Tool for easily deploying applications or configuration packaged in APK packages via SSH
Shell
3
star
77

collectd-apk

Collectd plugin for apk-tools
C
2
star
78

tash

WIP
Shell
2
star
79

acpi-utils

ACPI utilities for use in scripts and one-liners
Shell
2
star
80

gversion.lua

Lua library for Gentoo-style versioning format
Lua
2
star
81

nginx-oidc-njs

OpenID Connect and OAuth 2.0 module for NGINX written in njs.
TypeScript
2
star
82

jabber-migrate

Tool for migration of a roster from one Jabber server to another.
Java
2
star
83

alpine-git-mirror-syncd

Lua script that listens on MQTT and synchronizes Git mirrors when notified about changes
Lua
2
star
84

spring-modular

Modularize Spring applications simply!
Java
2
star
85

spring-security-oauth-samples

Modified samples from Spring Security OAuth project
Java
2
star
86

collectd-openrc

Collectd plugin for OpenRC
C
2
star
87

hass-smarwi

Home Assistant integration for Vektiva SMARWI window opener
Python
2
star
88

macos-init

Simplified cloud-init for macOS
Shell
2
star
89

com.meetfranz.Franz

Flatpak for Franz
1
star
90

prebackup

Pre/post backup scripts
Shell
1
star
91

slim-htag

Slim filter providing a heading tag with parametrized (dynamic) level (h1-h6)
Ruby
1
star
92

beuri-parser

Parser of Boolean Expressions in URI
Java
1
star
93

my-void-packages

My package templates for Void Linux
Shell
1
star
94

ts-transformer-export-default-name

TypeScript AST transformer that assigns name to anonymous functions and classes exported as default
TypeScript
1
star
95

ansible-modules

Some unofficial Ansible modules.
Python
1
star
96

roundcube-virtuser_ldap

A Roundcube plugin for LDAP based User-to-Email and Email-to-User lookup
PHP
1
star
97

sublimedsl

Simple pythonic DSL for generating Sublime Text configs.
Python
1
star
98

shaj

C
1
star
99

atom-jaxb

Custom JAXB classes for Atom Syndication Format
Java
1
star
100

nginx-jsconf

JS library and a CLI tool to convert nginx configuration from YAML or JSON to nginx config format
TypeScript
1
star