首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SSH权限被拒绝(公开密钥)

SSH权限被拒绝(公开密钥)
EN

Stack Overflow用户
提问于 2015-05-05 17:58:46
回答 2查看 43.9K关注 0票数 10

我想把Ubuntu的Debian变成一个SSH。我已经有了RSA密钥,这是我使用的相同的密钥,我的Git。

我使用以下方法将密钥从Ubuntu复制到Debian:

代码语言:javascript
复制
ssh-copy-id -i ~/.ssh/id_rsa.pub root@ip-address

然后,我对Debian上的sshd_config进行了修改,使其包括以下内容:

RSAAuthentication是 PubkeyAuthentication是 PasswordAuthentication号

我重新开始了我的SSH服务。现在我尝试将SSH从Ubuntu转移到

代码语言:javascript
复制
ssh -v root@ip-addr

但我得到了以下信息:

代码语言:javascript
复制
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只通过公开密钥身份验证来实现。

我读过与这个话题相关的每一篇文章,但没有一篇对我有用。这就是为什么我创建了一个单独的帖子。

编辑

StrictModesyes改为sshd_config中的no解决了这个问题。这样安全吗?

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

代码语言:javascript
复制
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]
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-05-05 18:02:56

您不希望提供.pub作为您的凭据。你想在你的头上使用你的私钥,所以你应该这么做。

代码语言:javascript
复制
ssh -v -i ~/.ssh/id_rsa root@ip-addr

这是要使用的deault键,所以您可以完全取消-i标志。

此外,如果要以root用户身份通过ssh登录,请确保您有PermitRootLogin yes

票数 11
EN

Stack Overflow用户

发布于 2015-05-05 18:56:55

我会做一个新的密钥对,并使用它。这只是在本地测试内容,但只需将.ssh目录转到远程服务器上,以使双向ssh成为可能,如果您只需要单向的话,那么在两个authorized_keys文件中都没有公钥:

代码语言:javascript
复制
$ 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.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30060046

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档