SSH login using Active Directory credentials

18,898

AllowGroups This keyword can be followed by a list of group name patterns, separated by spaces. If specified, login is allowed only for users whose primary group or supplementary group list matches one of the patterns. Only group names are valid; a numerical group ID is not recognized. By default, login is allowed for all groups. The allow/deny directives are processed in the following order: DenyUsers, AllowUsers, DenyGroups, and finally AllowGroups.

It looks like the Problem is the whitespace in the sshd_config, which is used as separator in the AllowGroups field. Although even not really documented, it should work to use double-quotes, using "IT Security".

https://bugzilla.mindrot.org/show_bug.cgi?id=482

For debugging groups id <username> and getent are always helpful to see if the users and groups are properly retrieved.

Also check the sssd.conf man page and verify how sssd handles whitespace in groups.

Share:
18,898

Related videos on Youtube

newyorkstateofmind
Author by

newyorkstateofmind

Updated on September 18, 2022

Comments

  • newyorkstateofmind
    newyorkstateofmind over 1 year

    I am having trouble logging into a Linux system via SSH using my Active Directory credentials. the system is bound to AD, and all of the required packages are installed and configured, but I cannot login. What am I missing here?

    I get the following errors in /var/log/secure:

    Mar  7 14:32:02 password sshd[4657]: User myusername from <anothersystem.mydomain.com> not allowed because none of user's groups are listed in AllowGroups
    Mar  7 14:32:02 password sshd[4657]: input_userauth_request: invalid user <myusername> [preauth]
    

    wbinfo -g lists all groups and wbinfo -u lists all users

    My configurations:

    /etc/pam.d/system-auth

    auth        required      pam_env.so
    auth        sufficient    pam_unix.so nullok try_first_pass
    auth        requisite     pam_succeed_if.so uid >= 500 quiet_success
    auth        sufficient    pam_sss.so use_first_pass
    auth        sufficient    pam_krb5.so use_first_pass
    auth        sufficient    pam_winbind.so cached_login use_first_pass
    auth        required      pam_deny.so
    
    account     required      pam_unix.so broken_shadow
    account     sufficient    pam_localuser.so
    account     sufficient    pam_succeed_if.so uid < 500 quiet
    account     [default=bad success=ok user_unknown=ignore] pam_sss.so
    account     [default=bad success=ok user_unknown=ignore] pam_krb5.so
    account     [default=bad success=ok user_unknown=ignore] pam_winbind.so    cached_login
    account     required      pam_permit.so
    
    password    requisite     pam_pwquality.so try_first_pass local_users_only    retry=3 authtok_type=
    password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
    password    sufficient    pam_sss.so use_authtok
    password    sufficient    pam_krb5.so use_authtok
    password    sufficient    pam_winbind.so use_authtok
    password    required      pam_deny.so
    
    session     optional      pam_keyinit.so revoke
    session     required      pam_limits.so
    session     optional      pam_systemd.so
    session     optional      pam_oddjob_mkhomedir.so umask=0077
    session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
    session     required      pam_unix.so
    session     optional      pam_sss.so
    session     optional      pam_krb5.so
    session     optional      pam_winbind.so cached_login
    

    cd /etc/sssd/sssd.conf

    [sssd]
    domains = mydomain.com
    config_file_version = 2
    services = nss, pam
    
    [domain/mydomain.com]
    ad_domain = mydomain.com
    krb5_realm = MYDOMAIN.COM
    realmd_tags = manages-system joined-with-samba
    cache_credentials = True
    id_provider = ad
    krb5_store_password_if_offline = True
    default_shell = /bin/bash
    ldap_id_mapping = True
    use_fully_qualified_names = True
    fallback_homedir = /home/%d/%u
    access_provider = simple
    simple_allow_groups = IT Security
    

    /etc/ssh/sshd_config

        #       $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $
    
        # This is the sshd server system-wide configuration file.  See
        # sshd_config(5) for more information.
    
        # This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin
    
        # The strategy used for options in the default sshd_config shipped with
        # OpenSSH is to specify options with their default value where
        # possible, but leave them commented.  Uncommented options override the
        # default value.
    
        # If you want to change the port on a SELinux system, you have to tell
        # SELinux about this change.
        # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
        #
        #Port 22
        #AddressFamily any
        #ListenAddress 0.0.0.0
        #ListenAddress ::
    
        # The default requires explicit activation of protocol 1
        #Protocol 2
    
        # HostKey for protocol version 1
        #HostKey /etc/ssh/ssh_host_key
        # HostKeys for protocol version 2
        HostKey /etc/ssh/ssh_host_rsa_key
        #HostKey /etc/ssh/ssh_host_dsa_key
        HostKey /etc/ssh/ssh_host_ecdsa_key
        HostKey /etc/ssh/ssh_host_ed25519_key
    
        # Lifetime and size of ephemeral version 1 server key
        #KeyRegenerationInterval 1h
        #ServerKeyBits 1024
    
        # Ciphers and keying
        #RekeyLimit default none
    
        # Logging
        # obsoletes QuietMode and FascistLogging
        #SyslogFacility AUTH
        SyslogFacility AUTHPRIV
        #LogLevel INFO
    
        # Authentication:
    
        #LoginGraceTime 2m
        #PermitRootLogin yes
        # Only allow root to run commands over ssh, no shell
        PermitRootLogin forced-commands-only
        #StrictModes yes
        #MaxAuthTries 6
        #MaxSessions 10
        AllowGroups IT Security
    
        #RSAAuthentication yes
        #PubkeyAuthentication yes
    
        # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
        # but this is overridden so installations will only check .ssh/authorized_keys
        AuthorizedKeysFile .ssh/authorized_keys
    
        #AuthorizedPrincipalsFile none
    
        #AuthorizedKeysCommand none
        #AuthorizedKeysCommandUser nobody
    
        # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
        #RhostsRSAAuthentication no
        # similar for protocol version 2
        #HostbasedAuthentication no
        # Change to yes if you don't trust ~/.ssh/known_hosts for
        # RhostsRSAAuthentication and HostbasedAuthentication
        #IgnoreUserKnownHosts no
        # Don't read the user's ~/.rhosts and ~/.shosts files
        #IgnoreRhosts yes
    
        # To disable tunneled clear text passwords, change to no here!
        #PasswordAuthentication yes
        #PermitEmptyPasswords no
        # EC2 uses keys for remote access
        PasswordAuthentication no
    
        # Change to no to disable s/key passwords
        #ChallengeResponseAuthentication yes
        ChallengeResponseAuthentication no
    
        # Kerberos options
        KerberosAuthentication yes
        #KerberosOrLocalPasswd yes
        KerberosTicketCleanup yes
        #KerberosGetAFSToken yes
        #KerberosUseKuserok yes
    
        # GSSAPI options
        GSSAPIAuthentication yes
        #GSSAPICleanupCredentials yes
        #GSSAPIStrictAcceptorCheck yes
        #GSSAPIKeyExchange no
        #GSSAPIEnablek5users no
    
        # Set this to 'yes' to enable PAM authentication, account processing,
        # and session processing. If this is enabled, PAM authentication will
        # be allowed through the ChallengeResponseAuthentication and
        # PasswordAuthentication.  Depending on your PAM configuration,
        # PAM authentication via ChallengeResponseAuthentication may bypass
        # the setting of "PermitRootLogin without-password".
        # If you just want the PAM account and session checks to run without
        # PAM authentication, then enable this but set PasswordAuthentication
        # and ChallengeResponseAuthentication to 'no'.
        # WARNING: 'UsePAM no' is not supported in Amazon Linux AMI and may cause several
        # problems.
        # Leaving enabled as described so that account and session checks are run
        UsePAM yes
    
        #AllowAgentForwarding yes
        #AllowTcpForwarding yes
        #GatewayPorts no
        X11Forwarding yes
        #X11DisplayOffset 10
        #X11UseLocalhost yes
        #PermitTTY yes
        #PrintMotd yes
        # Explicitly enable
        PrintLastLog yes
        #TCPKeepAlive yes
        #UseLogin no
        UsePrivilegeSeparation sandbox          # Default for new installations.
        #PermitUserEnvironment no
        #Compression delayed
        #ClientAliveInterval 0
        #ClientAliveCountMax 3
        #ShowPatchLevel no
        #UseDNS yes
        #PidFile /var/run/sshd.pid
        #MaxStartups 10:30:100
        #PermitTunnel no
        #ChrootDirectory none
        #VersionAddendum none
    
        # no default banner path
        #Banner none
    
        # Accept locale-related environment variables
        AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
        AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
        AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
        AcceptEnv XMODIFIERS
    
        # override default of no subsystems
        Subsystem sftp  /usr/libexec/openssh/sftp-server
    
        # Example of overriding settings on a per-user basis
        #Match User anoncvs
        #       X11Forwarding no
        #       AllowTcpForwarding no
        #       PermitTTY no
        #       ForceCommand cvs server
    
    • Michael Hampton
      Michael Hampton about 8 years
      The error message is self-explanatory. First, you should read it, and then you should look at the directive it mentions, and then you should do the needful.
    • newyorkstateofmind
      newyorkstateofmind about 8 years
      @MichaelHampton That's what I thought, but the error persists even after adding the group and/or user to my sssd config.
    • Michael Hampton
      Michael Hampton about 8 years
      I suspect that you didn't actually do the needful. Which group is this user in?
    • newyorkstateofmind
      newyorkstateofmind about 8 years
      The user is a member of the 'IT Security' group in Active Directory. Not a member of any local groups.
    • Michael Hampton
      Michael Hampton about 8 years
      But you have defined two allowed groups, "IT" and "Security". Not "IT Security".
    • newyorkstateofmind
      newyorkstateofmind about 8 years
      It's actually one group. I thought I accounted for the space between IT and security by specifying the carat between the two words.
    • Paul Haldane
      Paul Haldane about 8 years
      I don't see any caret in the group reference in the posted sssd and sshd config files
    • newyorkstateofmind
      newyorkstateofmind about 8 years
      What is the correct syntax for adding an AD user group with a space in it's name?