【问题标题】:CentOS scp without password not working没有密码的CentOS scp不起作用
【发布时间】:2011-07-12 05:23:15
【问题描述】:

我一直在尝试使用 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

【问题讨论】:

  • 您为哪个用户设置了授权密钥。在远程框上,它需要用于您尝试连接的用户。 root 的授权密钥不适用于所有用户。
  • 您是否更改了框 2 的 ssh_config 以便 ssh 尝试 pubkey auth?
  • 另外,我会使用 -v 标志运行 scp 以获得详细输出。这对调试很有帮助。
  • 如何更改配置以尝试 pubkey?

标签: ssh amazon-web-services amazon-ec2 centos public-key


【解决方案1】:

您的授权密钥行应该是

AuthorizedKeysFile     %h/.ssh/authorized_keys

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

【讨论】:

  • 感谢您的收获。我对我的 /etc/ssh/sshd_config 进行了更改并重新启动 /sbin/service sshd restart ,但我仍然无法连接。
【解决方案2】:

更新 - 已修复

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

这是 RH 的一个已知问题,目录被错误标记并且 PAM 在作为 init 脚本运行时阻止 sshd 读取 authorized_hosts。如果您偶然发现/var/log/audit/audit.log,您会看到错误。似乎很少见,但发生时会很痛苦!

更多详情https://bugzilla.redhat.com/show_bug.cgi?id=499343

原帖

我刚刚遇到了这个问题。我有一个调整不佳的 VirtualBox(我没有告诉 vbox 使用 64 位)——当我克隆并重新启动(在 vbox RedHat 64 位模式下)时,它开始要求我输入密码。

原始图像很好——具有相同的设置——所以我认为与网络相关的建议可能是相关的,或者与服务器密钥有关。

然而,奇怪的是,如果在盒子上,我杀死了自动启动的 sshd 进程,然后以 root 身份手动运行 /usr/sbin/sshd,我可以无密码登录。 一个愚蠢的解决方法,但可用。

所以这是 /etc/init.d/sshd 问题。但我一直无法追查它是什么......我尝试过删除该脚本中的大部分内容,但在调用 /etc/init.d/sshd start 时仍会提示输入密码,但在 /usr/sbin/sshd 时不会提示。

也许这些 cmets 可以提供帮助,然后有人可以提供进一步的帮助!?

【讨论】:

    【解决方案3】:

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

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

    【讨论】:

    • 他的调试输出没有提到 GSS。我认为这不是问题。
    【解决方案4】:

    我认为这个链接会解决你的问题,我用它来解决我的 ssh 不登录问题。关键是跑 ssh root@node02 'restorecon -R -v /root/.ssh' 此命令将修复 SE http://blog.firedaemon.com/2011/07/27/passwordless-root-ssh-public-key-authentication-on-centos-6/

    【讨论】:

      【解决方案5】:

      按照前面的步骤,我必须在 .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

      成功了!

      谢谢。达米安

      【讨论】:

        【解决方案6】:

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

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

        chmod 700 ~/.ssh
        

        接下来,进入/etc/ssh/sshd_config,将StrictModes yes改为StrictModes no。如果被注释掉了,那么在文件中专门添加StrictModes no

        这解决了问题。

        【讨论】:

          【解决方案7】:

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-05-07
            • 1970-01-01
            • 2012-11-03
            • 2011-09-27
            • 1970-01-01
            • 1970-01-01
            • 2017-09-20
            • 1970-01-01
            相关资源
            最近更新 更多