3

我一直在尝试使用 ssh 公钥从一个EC2 实例连接到另一个实例,并且经历了一段非常艰难的时期。

这是场景:我需要在脚本中让框 2 scp 来自框 1 的文件。这个脚本需要能够在没有密码的情况下进行 scp,所以我需要设置公钥。

在框 2 我运行ssh-keygen –t rsa并生成id_rsaid_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
4

7 回答 7

1

UPDATE - FIXED IT

restorecon -R -v -d /root/.ssh

This is a known issue with RH where directories get mislabelled and PAM prevends sshd from reading authorized_hosts when run as init script. You'll see the errors if you stumble across /var/log/audit/audit.log. Rare it seems but painful when it happens!

More details at https://bugzilla.redhat.com/show_bug.cgi?id=499343

ORIGINAL POST

I've just hit what looks like exactly this problem. I had a poorly tuned VirtualBox (I hadn't told vbox to use 64bit) -- which when I cloned and restarted (in vbox RedHat 64-bit mode), started asking me for a password.

The original image was fine -- with identical settings -- so I think the suggestion of being networking-related might be relevant, or else to do with server keys.

The weird thing however is that if on the box, I kill the sshd process which autostarted, then manually run /usr/sbin/sshd as root, I can log in passwordless fine. A silly workaround, but usable.

So it is an /etc/init.d/sshd issue. But I haven't been able to track down what it is ... have tried chucking out most of the stuff in that script but it still prompts for password when invoked as /etc/init.d/sshd start but not when at /usr/sbin/sshd.

Maybe these comments can help, and someone can then help further!?

于 2012-11-02T19:06:34.107 回答
1

您的授权密钥行应该是

AuthorizedKeysFile     %h/.ssh/authorized_keys

服务器正在为您的服务器查找错误的目录。

于 2011-03-09T20:31:53.280 回答
0

我遇到了完全相同的问题,整个下午都在挠头。原来是一个小的 sshd_config 文件问题。

首先,将远程主机的.ssh文件夹上的访问模式更改为仅限用户访问。

chmod 700 ~/.ssh

接下来,转到 /etc/ssh/sshd_config,更改StrictModes yesStrictModes no. 如果它被注释掉,那么专门添加StrictModes no到文件中。

这解决了这个问题。

于 2014-02-08T01:22:55.010 回答
0

按照前面的步骤后,我必须在 .ssh 文件夹中将权限设置为“..”:

一旦我有〜/ .ssh:

drwx-------- 2 build build 4096 Nov 4 14:35 。

drwx------ 6 build build 4096 Nov 4 14:34 ..

-rw------- 1 build build 400 Nov 4 14:35 authorized_keys

有效!

谢谢。达米安

于 2013-11-04T14:27:39.833 回答
0

我认为这个链接可以解决你的问题,我用它来解决我的 ssh 不登录问题。关键是运行 ssh root@node02 'restorecon -R -v /root/.ssh' 这个命令将修复 SE http://blog.firedaemon.com/2011/07/27/passwordless-root-ssh-public- centos-6上的密钥认证/

于 2011-12-21T05:24:10.400 回答
0

尝试从 ~/.ssh/known_hosts 中删除 box1 IP,使其更新。由于可能的“中间人”攻击,ssh 可能会禁用密钥身份验证。

如果没有帮助, GSSAPIAuthentication no 请在 /etc/ssh/ssh_config 文件中添加一行。

于 2011-03-09T20:41:34.660 回答
0

我刚刚发现的另一件事是,我必须编辑 .ssh/authorized_keys 文件并使主机名完全合格。否则,我无法在 scp/ssh 命令中使用完全限定名称。现在两个完全限定(如“host.company.com”)和相对名称(“host”)都可以工作,因为两个主机都在“company.com”域中。ssh-keygen 仅使用主机名创建了公钥文件。

于 2017-02-06T18:46:01.853 回答