mat*_*l42 6 ssh ldap authentication
环境: Ubuntu 14.04 和 16.04 服务器、Windows Server 2016 上的 Active Directory、Ubuntu 14.04 和 16.04 客户端。Ubuntu 服务器和客户端不在域中。
大家好,
我对实现 ssh ldap 身份验证的所有方法都有些迷茫。但是我找不到适合我的。
我的愿望:我不想通过使用“sAMAccount@serverIP”登录来连接到我的服务器,我的 SSH 密钥存储在我的 AD 中(添加为 odiSSHPubKeys 的新字段)。我的服务器与我的 AD(ldapsearch 查询)通信良好。我通过更新我的 sshdconfig 实现了这一点:
/etc/ssh/sshd_config
AuthorizedKeysCommand /usr/bin/auth
AuthorizedKeysCommandUser root
Run Code Online (Sandbox Code Playgroud)
/usr/bin/auth
#!/bin/bash
cn=$1
server=ldap.myad.net #Put your server IP
basedn=dc=mydomain,dc=net #Put your basedn
port=389
bindUser=myBindUser
bindPass=myBindUserPassword
#cn=mathieu
ldapsearch -LLL -o ldif-wrap=no -x -h $server -p $port -b $basedn -D $bindUser -w $bindPass -s sub "(sAMAccountName=$cn)" | sed -n 's/^[ \t]*odiSSHPubKeys:[ \t]*\(.*\)/\1/p'
Run Code Online (Sandbox Code Playgroud)
当我连接到 mathieu@192.168.0.231 时,我被 preauth 踢了
/var/log/auth.log
Apr 18 11:56:26 MLL-HV-UBU-16 sshd[9103]: Invalid user mathieu from 192.168.0.114
Apr 18 11:56:26 MLL-HV-UBU-16 sshd[9103]: input_userauth_request: invalid user mathieu [preauth]
Apr 18 11:56:26 MLL-HV-UBU-16 sshd[9103]: Connection closed by 192.168.0.114 port 50152 [preauth]
Run Code Online (Sandbox Code Playgroud)
所以我的问题是“mathieu”在我的 Ubuntu 服务器上不作为用户存在。我尝试在我的 /usr/bin/auth 中强制我的 cn 并使用 root 帐户(root@192.168.0.231)登录并且它有效,所以我的 /usr/bin/auth id 很好。
如何禁用 preauth 检查以让 ldap 工作?
PS:我不想要登录/密码身份验证(对于这个解决方案,有很多教程,但对于 ssh 密钥或旧密钥的教程并不多)。
谢谢你的帮助
小智 6
最好的选择是为此目的使用 sssd。我使用 AltSecurityIdentities 来存储密钥并使用 reald 将服务器加入域。
加入域后,将以下内容添加到 [domain/] 部分下的 /etc/sssd/sssd.conf 文件中:
ldap_user_extra_attrs = altSecurityIdentities:altSecurityIdentities
ldap_user_ssh_public_key = altSecurityIdentities
ldap_use_tokengroups = 真
并在 [sssd] 部分下添加:
服务 = nss、pam、sudo、ssh
然后到 /etc/ssh/sshd_config 添加:
AuthorizedKeysCommand /usr/bin/sss_ssh_authorizedkeys
AuthorizedKeysCommandUser root
重新启动这两个服务,您应该可以使用 AD 用户名和 AD 中 AltSecurityIdentities 扩展属性中存储的密码登录。