【发布时间】:2018-05-23 23:28:09
【问题描述】:
我在 2 个独立的网络上有 2 个 Pi,运行 raspbian,一个是 Web 服务器,另一个用于备份(比如说 pi-server 和 pi-backup),我希望 pi-server ssh 到 pi -backup 以备份数据。我设法在 pi-server 上输入这个:
ssh -p 4444 userBackup@pibackup.fr
userBackup@pibackup.fr's password :
我输入我的密码,然后我在 pi-backup 上得到提示,一切都很好(pi-backup 的 ssh 在 22 上侦听,但我用路由器将 4444 重定向到 22,听说它更安全)
由于我想编写 connexion 脚本以便能够每天 cron 它,我无法通过密码进行身份验证,所以我尝试了密钥:我在 pi-server 上使用
生成了一个密钥ssh-keygen
然后我将 id_rsa_pub 复制/粘贴到 /home/userBackup/.ssh/authorized_keys... 但是当我尝试连接时仍然要求我输入密码。
令我惊讶的是,我已经使用来自我的主 PC 的密钥(当然不同)连接到 pi-backup,这与 pi-backup 位于同一本地网络上。所以我在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”,所以我尝试使用我的公钥,但没有任何改变。
【问题讨论】:
-
你应该调用
ssh-add在pi-seserver上添加你的密钥然后你可以使用ssh而不需要密码。 -
当我尝试得到“无法打开与您的身份验证代理的连接”时。无论我是否尝试使用 sudo
-
哦,好的!那你必须先做:
eval `ssh-agent`。在您的 cron 文件中,您不需要(我认为)这样做。
标签: networking ssh raspberry-pi raspbian