我正在尝试从Ubuntu SSH到Debian。我已经有了RSA密钥;它与我使用Git时使用的密钥相同。
我使用以下方法将密钥从Ubuntu复制到Debian:
ssh-copy-id -i ~/.ssh/id_rsa.pub root@ip-address
然后我在Debian上修改了sshd_config
以包含以下内容:
RSAAuthentication yes
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).
我基本上只想通过publickey身份验证强制SSH。
我已阅读与此主题相关的所有其他帖子,但这些帖子都不适合我。这就是为什么我把它创建为一个单独的帖子。
修改
在StrictModes
中将yes
从no
更改为sshd_config
解决了问题。这样做安全吗?
编辑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]
答案 0 :(得分:5)
您不希望将.pub作为凭据提供。你想在你的最后使用你的私钥,所以你可能应该这样做
ssh -v -i ~/.ssh/id_rsa root@ip-addr
这是要使用的deault键,所以你可以完全不用-i
标志
此外,如果您要通过ssh以root身份登录,请确保您拥有PermitRootLogin yes
答案 1 :(得分:0)
我会组成一个新的密钥对并使用它代替。这只是在本地测试东西,但只是简单地将.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.