# How to Join an Active Directory with NixOS

**URL:** https://discourse.nixosstag.fcio.net/t/how-to-join-an-active-directory-with-nixos/63339
**Category:** Guides
**Created:** [April 22, 2025, 1:35pm UTC](https://discourse.nixosstag.fcio.net/t/how-to-join-an-active-directory-with-nixos/63339 "2025-04-22T13:35:43Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![liberodark](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/liberodark/32/11901_2.png) [@liberodark](https://discourse.nixosstag.fcio.net/u/liberodark)
#### Post date: [April 22, 2025, 1:35pm UTC](https://discourse.nixosstag.fcio.net/t/how-to-join-an-active-directory-with-nixos/63339/1 "2025-04-22T13:35:43Z")

</div>

Hello,

Here’s how to create a connection to an Active Directory with NixOS.

## The first part involves activating krb5:

```bash
nixos-rebuild switch

```

## Here is the complete configuration:

```nix
{ config, pkgs, ... }:

{
  networking.hostName = "myserver";
  networking.domain = "server.com";

  services.realmd.enable = true;
  programs.oddjobd.enable = true;

  # Enable SSSD
  services.sssd = {
    enable = false;
    config = ''
      [sssd]
      config_file_version = 2
      domains = server.com
      services = nss, pam

      [domain/server.com]
      default_shell = /run/current-system/sw/bin/bash
      krb5_store_password_if_offline = true
      cache_credentials = true
      krb5_realm = SERVER.COM
      realmd_tags = manages-system joined-with-adcli
      id_provider = ad
      fallback_homedir = /home/%u
      ad_domain = server.com
      use_fully_qualified_names = false
      ldap_id_mapping = true
      access_provider = simple
      simple_allow_groups = admins@server.com
      auth_provider = ad
    '';
  };

  environment.etc."krb5.conf".mode = "0644";

  # Enable Kerberos
  security.krb5 = {
    enable = true;
    settings = {
      libdefaults = {
        default_realm = "SERVER.COM";
        ticket_lifetime = "24h";
        renew_lifetime = "7d";
        dns_lookup_realm = false;
        udp_preference_limit = "0";
      };
    };
  };

  # Enable PAM
  security.pam.krb5.enable = false;
  security.pam.services = {
    sshd.sssdStrictAccess = true;
    sshd.makeHomeDir = true;
    login.sssdStrictAccess = true;
  };

  # List packages installed in system profile
  environment.systemPackages = with pkgs; [
    # Core
    vim
    # AD
    adcli
    krb5
    realmd
    samba
    sssd
  ];

  # Enable SSH
  services.openssh = {
    enable = true;
    settings = {
      PermitRootLogin = "no";
      PasswordAuthentication = true;
      KbdInteractiveAuthentication = true;
      UsePAM = true;
      PermitEmptyPasswords = false;
    };
  };

}

```

## The second part is initiating authentication:

```bash
adcli join server.com -U administrator@SERVER.COM
kinit administrator@SERVER.COM

```

## The third part is activating SSSD:

Now you can modify the configuration to set SSSD to true.

From:

```nix
services.sssd = {
  enable = false;

```

To:

```nix
services.sssd = {
  enable = true;

```

Then apply the change:

```bash
nixos-rebuild switch

```

## You can now test with:

```bash
realm list

```

Output:

```auto
server.com
  type: kerberos
  realm-name: SERVER.COM
  domain-name: server.com
  configured: kerberos-member
  server-software: active-directory
  client-software: sssd
  required-package: oddjob
  required-package: oddjob-mkhomedir
  required-package: sssd
  required-package: adcli
  required-package: samba-common-tools
  login-formats: %U
  login-policy: allow-permitted-logins
  permitted-logins: 
  permitted-groups: admins@server.com

```

And:

```bash
id my.userad

```

Output:

```auto
uid=1994001241(my.userad) gid=1994000513(domain users) groups=1994000513(domain users)

```

For French Users :

> **[Rejoindre un Active Directory avec NixOS - LinuxOS - Forum](https://forum.linuxos.ovh/d/232-rejoindre-un-active-directory-avec-nixos)**
>
> Linux - Gaming - Hacking
