【发布时间】:2011-07-12 05:23:15
【问题描述】:
我一直在尝试使用 ssh 公钥从一个 EC2 实例 连接到另一个实例,但一直很艰难。
这是场景: 我需要在脚本中让框 2 scp 来自框 1 的文件。这个脚本需要能够在没有密码的情况下进行 scp,所以我需要设置公钥。
在框 2 上,我运行 ssh-keygen –t rsa 并生成 id_rsa 和 id_rsa.pub
我将 id_rsa.pub 复制到框 1
我将 id_rsa.pub 移动到 .ssh 并运行 cat id_rsa.pug >> authorized_keys
我将两个盒子上所有 .ssh 目录的权限更改为 700,并将文件本身的权限更改为 600。
我已将框 1 上的 sshd_config 设置更改为:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
然后重启ssh
/sbin/service sshd restart
当我尝试从 box1 scp 或 ssh 进入 box1 时,我收到错误:
Address 67.22.33.1 maps to ec2-67-22-33-1.compute-1.amazonaws.com, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
tomcat@tomcat1.****.com's password:
有什么想法吗?
我进行了更改并尝试 scp 到 tomcat1,但它失败了。这是输出:
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to tomcat1.****.com [67.22.33.15] port 22.
debug1: Connection established.
debug1: identity file /home/tomcat/.ssh/identity type -1
debug1: identity file /home/tomcat/.ssh/id_rsa type 1
debug1: identity file /home/tomcat/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
The authenticity of host 'tomcat1.****.com (67.22.33.15)' can't be established.
RSA key fingerprint is 5a:3e:fe:be:b8:0e:05:63:bf:ab:c8:4f:e5:91:db:a0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'tomcat1.****.com,67.22.33.15' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
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: Trying private key: /home/tomcat/.ssh/identity
debug1: Offering public key: /home/tomcat/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/tomcat/.ssh/id_dsa
debug1: Next authentication method: password
【问题讨论】:
-
您为哪个用户设置了授权密钥。在远程框上,它需要用于您尝试连接的用户。 root 的授权密钥不适用于所有用户。
-
您是否更改了框 2 的 ssh_config 以便 ssh 尝试 pubkey auth?
-
另外,我会使用 -v 标志运行 scp 以获得详细输出。这对调试很有帮助。
-
如何更改配置以尝试 pubkey?
标签: ssh amazon-web-services amazon-ec2 centos public-key