系统:centos6.5
openssl版本:6.9p1
/etc/ssh/sshd_config配置文件做以下修改:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysCommand /usr/bin/ldap_ssh_key.sh
AuthorizedKeysCommandUser nobody
然后赋予 /usr/bin/ldap_ssh_key.sh 文件 755 的权限。
ldap_ssh_key.sh脚本代码:
#!/bin/bash
if [ "$1" == "wangqilong" ]; then
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAveKaks3F9A+DdN7G3+cHvZU/s4cvXbTS/Pm3BNzS4NTtijRJFp69131XabF0Bokm/sR9+Nvtrmlf5/QTFXpcvPCuzg/DCgOGR3EX7kRP7BrYSKGCnlC3DLpxDJaSPA39nDSujfdPTVl+IhdSctxegf95mfC/HIXdCrdOgiijAH7Osy8V1ljUEMeRnWVLq0G9twWUEi93ncSJjzKRLnAO8YlMQk/yLrVPkeHBFuxA04d/9PAN8qcrA4dz2uAJXPSaz1E1iCn0tgRAtWjPzHJCKlJcJZQ4h5ku03IPwReWX2Hcuxf3DaEH9+9xnMwU7DVtHGMMqolxW5rP2kFD5KVclQ=="
fi
其实脚本主要是输出用户的公钥key的内容。可以查询数据库,可以查询LDAP。查询数据库例子如下: