我在两个不同的网络上有两个Pi,运行raspbian,一个是web服务器,另一个用来备份(比如pi服务器和pi备份),为了备份数据,我希望pi服务器从ssh到pi备份。我设法在pi-server上键入以下内容:
ssh -p 4444 userBackup@pibackup.fr
userBackup@pibackup.fr's password :我输入我的密码,然后提示我做pi备份,一切都很好(pi备份的ssh监听22,但是我用我的路由器重定向4444到22,听说它更安全)
由于我希望编写连接的脚本,以便能够每天对其进行cron处理,所以我无法通过密码进行身份验证,所以我尝试了密钥:我使用pi-server生成了一个密钥。
ssh-keygen然后我在/home/userBackup/..ssh/ id_rsa_pub _key中复制/粘贴.但是当我尝试连接时,我仍然被要求提供一个密码。
令我惊讶的是,我已经用一个键(当然是不同的键)连接到pi-备份,它与我的主PC连接在同一个本地网络上,而不是pi-备份。所以我在authorized_keys中有两行。
你知道会出什么问题吗?不在同一个本地网络上不应该是个问题,对吗?
当我尝试时编辑
ssh -v -i ~/.ssh/id_rsa -p 4444 userBackup@pibackup.fr我得到的是:
OpenSSH_6.0p1 Debian-4+deb7u2, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to pibackup.fr [90.10.1.1] port 4444.
debug1: Connection established.
debug1: identity file /home/userServer/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/userServer/.ssh/id_rsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.7p1 Raspbian-5
debug1: match: OpenSSH_6.7p1 Raspbian-5 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.0p1 Debian-4+deb7u2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 6b:5f:aa:aa:aa0c:aa:33:97:aa:56:aa:39:00:6f:79
debug1: Host '[pibackup.fr]:4444' is known and matches the ECDSA host key.
debug1: Found key in /home/userBackup/.ssh/known_hosts:2
Warning: Permanently added the ECDSA host key for IP address '[90.10.1.1]:4444' to the list of known hosts.
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,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/userServer/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
userBackup@piBackup.fr's password: 我注意到,在最后一行中,他说“提供RSA公钥:/home/userServer/..ssh/id_rsa”,所以我尝试使用公钥,但没有什么改变。
发布于 2015-12-14 08:01:16
我终于发现了这个问题:在serverBackup上,userBackup不是authorized_keys的所有者.仅此而已;)我仍然不明白为什么当我从局域网的PC连接时,它是工作,但现在一切都很好!Ankirama,谢谢你的时间和建议。
发布于 2015-12-12 11:27:02
必须在ssh-keygen行中指定用ssh生成的密钥。你可以这样做:
ssh -i ~/.ssh/blah.key -p 4444 userBackup@pibackup.fr它将加载您的密钥。
我希望它能帮到你。
https://stackoverflow.com/questions/34239189
复制相似问题