SSH权限被拒绝(publickey)

我正在尝试SSH从Debian到Debian。 我已经有一个RSA密钥; 我使用的是同样的密钥获得了我的Git。

我使用以下命令将密钥从Ubuntu复制到Debian:

ssh-copy-id -i ~/.ssh/id_rsa.pub root@ip-address 

然后,我修改了Debian上的sshd_config以包含以下内容:

RSAAuthentication是

PubkeyAuthentication yes

PasswordAuthentication no

我重新启动了我的SSH服务。 现在我尝试从Ubuntu使用SSH进入

 ssh -v root@ip-addr 

但我得到以下内容:

 OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug1: Connecting to 10.0.1.64 [10.0.1.64] port 22. debug1: Connection established. debug1: identity file /home/koushatalebian/.ssh/id_rsa.pub type 1 debug1: identity file /home/koushatalebian/.ssh/id_rsa.pub-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-8 debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0p1 Debian-4+deb7u2 debug1: match: OpenSSH_6.0p1 Debian-4+deb7u2 pat OpenSSH* compat 0x04000000 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: sending SSH2_MSG_KEX_ECDH_INIT debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ECDSA e2:af:83:f8:df:e2:15:db:77:30:e1:6b:e7:dc:77:99 debug1: Host '10.0.1.64' is known and matches the ECDSA host key. debug1: Found key in /home/koushatalebian/.ssh/known_hosts:10 debug1: ssh_ecdsa_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 RSA public key: /home/koushatalebian/.ssh/id_rsa.pub debug1: Authentications that can continue: publickey debug1: No more authentication methods to try. Permission denied (publickey). 

我基本上想强制SSH只发生通过公钥authentication。

我已经阅读了与此主题相关的所有其他post,而他们都没有为我工作。 这就是为什么我创build这个作为一个单独的职位。

编辑

sshd_config中将StrictModesyes更改为no修复了问题。 这是安全的吗?

编辑2这是服务器上的SSH日志:

 May 5 18:23:55 lemaker sshd[2591]: Connection from 10.0.1.37 port 42748 May 5 18:23:55 lemaker sshd[2591]: debug1: PAM: setting PAM_RHOST to "10.0.1.37" May 5 18:23:55 lemaker sshd[2591]: Failed publickey for root from 10.0.1.37 port 42748 ssh2 May 5 18:23:55 lemaker sshd[2591]: Connection closed by 10.0.1.37 [preauth] 

你不想提供你的.pub作为你的凭据。 你想在你的末端使用你的私钥,所以你应该做的

 ssh -v -i ~/.ssh/id_rsa root@ip-addr 

这是使用的重要的关键,所以你可以完全放弃-i标志

此外,确保你有PermitRootLogin yes如果你要通过SSH登录作为根

我会组成一个新的密钥对,并用它来代替。 这只是在本地测试的东西,但只需tar的.ssh目录,并把它放在远程服务器上,使双向ssh可能,如果你只想单向,那么在authorized_keys文件中没有公钥:

 $ pwd /home/testuser $ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/testuser/.ssh/id_rsa):[ENTER] Created directory '/home/testuser/.ssh'. Enter passphrase (empty for no passphrase):[ENTER] Enter same passphrase again:[ENTER] Your identification has been saved in /home/testuser/.ssh/id_rsa. Your public key has been saved in /home/testuser/.ssh/id_rsa.pub. [...] $ cd .ssh $ ls -l total 8 -rw------- 1 testuser testuser 1679 May 5 13:49 id_rsa -rw-r--r-- 1 testuser testuser 401 May 5 13:49 id_rsa.pub $ cat id_rsa.pub >> authorized_keys $ ssh 127.0.0.1 The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established. ECDSA key fingerprint is 0f:dd:ed:e3:bf:a1:c8:3f:fd:b2:0d:e8:1f:ee:29:f8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '127.0.0.1' (ECDSA) to the list of known hosts. Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.16.0-36-generic x86_64) [...] Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. $ exit Connection to 127.0.0.1 closed.