当服务器中的用户没有login到SSH给:权限被拒绝(公钥)

我正在使用公钥authenticationbuild立一个SSH服务器。 为此,我使用了这个教程: http : //www.g-loaded.eu/2005/11/10/ssh-with-keys/

我能够通过SSHlogin。 但是,这只有当我保持用户login到服务器(这意味着我必须在服务器上input我的用户名和密码,并保持login状态)。 如果我注销用户在服务器上,当我尝试通过SSHlogin它给出:“权限被拒绝(公钥)”。

我的问题是…是否真的需要保持用户login到服务器使用SSH公钥身份validation? 或者我做错了什么?

谢谢!

附加信息:使用

ssh [email protected] -v 

我得到以下输出(当没有用户login到服务器)。

 debug1: Reading configuration data /etc/ssh_config debug1: /etc/ssh_config line 20: Applying options for * debug1: Connecting to 10.0.1.200 [10.0.1.200] port 22. debug1: Connection established. debug1: identity file /Users/thecommodore/.ssh/id_rsa type -1 debug1: identity file /Users/thecommodore/.ssh/id_rsa-cert type -1 debug1: identity file /Users/thecommodore/.ssh/id_dsa type -1 debug1: identity file /Users/thecommodore/.ssh/id_dsa-cert type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1 debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_5.9 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-ctr hmac-md5 none debug1: kex: client->server aes128-ctr hmac-md5 none debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP debug1: SSH2_MSG_KEX_DH_GEX_INIT sent debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY debug1: Server host key: DSA 2e:ca:e6:66:d1:61:35:7c:98:bb:cb:1f:49:aa:24:81 debug1: Host '[10.0.1.200]:22' is known and matches the DSA host key. debug1: Found key in /Users/thecommodore/.ssh/known_hosts:7 debug1: ssh_dss_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: Roaming not allowed by server debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey debug1: Offering DSA public key: /Users/thecommodore/.ssh/id_dsa debug1: Authentications that can continue: publickey debug1: Trying private key: /Users/thecommodore/.ssh/id_rsa debug1: Trying private key: /Users/thecommodore/.ssh/id_dsa debug1: key_parse_private_pem: PEM_read_PrivateKey failed debug1: read PEM private key done: type <unknown> debug1: read PEM private key done: type DSA Identity added: /Users/thecommodore/.ssh/id_dsa (/Users/thecommodore/.ssh/id_dsa) debug1: read PEM private key done: type DSA debug1: Authentications that can continue: publickey debug1: No more authentication methods to try. Permission denied (publickey). 

这可能是encryption主目录的结果。 这会阻止SSH守护进程读取密钥文件,并导致基于密钥的login失败。 你基本上有两个select来缓解这个问题:

  • 禁用主目录encryption。 看到这个Tutoria (由OP提供)。
  • configurationSSH守护进程从另一个未encryption的位置读取密钥文件。

对于第二个选项,您可以为每个用户创build一个目录/sshkeys/和子目录。 然后将/etc/ssh/sshd_configAuthorizedKeysFile参数设置为/sshkeys/%u/authorized_keys ,并将这些文件放在适当的子目录中,并确保每个用户都拥有/sshkeys读/执权限,目录属于相应的用户并被设置为权限700

另一个更高级的选项是使用AuthorizedKeysCommand参数,并为密钥编写一个lookup-script,例如从LDAP目录。 这对于Thorsten提出的NFS4 / Kerberos问题也有帮助。 这将要求您允许用户将密钥放入相关的LDAP字段中,例如使用一些其他帮助程序脚本。

从使用强身份validation(Kerberized NFSv4,CIFS)的networking共享获取您的家庭可能会导致同样的问题。 PAM将使用您的密码来安装共享。 没有密码 – >没有家 – >没有authorized_keys