3 releases

0.0.3 Jan 19, 2022
0.0.2 May 4, 2020
0.0.1 May 1, 2020

#16 in #pam

Download history 4762/week @ 2024-01-03 5341/week @ 2024-01-10 5335/week @ 2024-01-17 4888/week @ 2024-01-24 5824/week @ 2024-01-31 7656/week @ 2024-02-07 3991/week @ 2024-02-14 3166/week @ 2024-02-21 4257/week @ 2024-02-28 4269/week @ 2024-03-06 5387/week @ 2024-03-13 7126/week @ 2024-03-20 6906/week @ 2024-03-27 6387/week @ 2024-04-03 7332/week @ 2024-04-10 5122/week @ 2024-04-17

26,744 downloads per month
Used in 2 crates (via pam)


90 lines

pam - Safe Rust API to the Linux Pluggable Authentication Modules (PAM)

Crates.io Documentation Build Status License

Note: Currently only supports basic username/password authentication out-of-the-box.


Environment support through the env module is probably broken and should not be used in the current state!


  1. Add pam to your Cargo.toml:
pam = "0.7.0"
  1. Use the Authenticator struct to authenticate and open a session
extern crate pam;
pub fn main() {
        let service = "<yourapp>";
        let user = "<user>";
        let password = "<pass>";

        let mut auth = pam::Authenticator::with_password(service).unwrap();
        auth.handler_mut().set_credentials(user, password);
        if auth.authenticate().is_ok() && auth.open_session().is_ok() {
            println!("Successfully opened a session!");
        else {
            println!("Authentication failed =/");


  • Implement basic user/password authentication
  • Add Authenticator struct
  • Add (more) documentation
  • Verify current conv does not leak memory
  • Allow custom conv functions to be passed
  • Code cleanup

Supported Rust versions

The library is only continuously built against Rust stable, beta and nightly but as it does not use a lot of new language features it should probably compile on older versions as well. If you encounter problems building on older versions and a small fix can be applied to make the build succeed, consider opening a pull request.

Note about stability

This crate follows semantic versioning. As such all versions below 1.0.0 should be considered development versions. This means the API could change any time.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~33K SLoC