Ssh 没有密码的CentOS scp不工作

Ssh 没有密码的CentOS scp不工作,ssh,amazon-web-services,amazon-ec2,centos,public-key,Ssh,Amazon Web Services,Amazon Ec2,Centos,Public Key,我一直在尝试使用ssh公钥从一个EC2实例连接到另一个实例,这段时间非常艰难 以下是场景: 我需要有一个脚本中的框2 scp一个来自框1的文件。这个脚本将需要能够scp没有密码,所以我需要设置公钥 在框2中,我运行了ssh keygen–t rsa并生成了id\u rsa和id\u rsa.pub 我将id\u rsa.pub复制到框1 我将id\u rsa.pub移动到.ssh并运行cat id\u rsa.pug>>授权密钥 我将所有.ssh目录在这两个框上的权限都更改为700,文件本身的权

我一直在尝试使用ssh公钥从一个EC2实例连接到另一个实例,这段时间非常艰难

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

在框2中,我运行了
ssh keygen–t rsa
并生成了
id\u rsa
id\u rsa.pub
我将
id\u rsa.pub
复制到框1 我将
id\u rsa.pub
移动到.ssh并运行
cat id\u rsa.pug>>授权密钥
我将所有.ssh目录在这两个框上的权限都更改为700,文件本身的权限更改为600。 我已将框1上的sshd_配置设置更改为:

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
debug1:读取配置数据/etc/ssh/ssh\u config
debug1:将选项应用于*
debug1:连接到tomcat1.***.com[67.22.33.15]端口22。
debug1:已建立连接。
debug1:identity file/home/tomcat/.ssh/identity-type-1
debug1:identity file/home/tomcat/.ssh/id\u rsa类型1
debug1:identity file/home/tomcat/.ssh/id_dsa type-1
debug1:加载了3个键
debug1:远程协议版本2.0,远程软件版本OpenSSH_4.3
debug1:match:OpenSSH_4.3 pat OpenSSH*
debug1:启用协议2.0的兼容模式
debug1:本地版本字符串SSH-2.0-OpenSSH_4.3
debug1:SSH2\u MSG\u KEXINIT已发送
debug1:SSH2\u MSG\u KEXINIT已收到
debug1:kex:server->client aes128 cbc hmac-md5无
debug1:kex:client->server aes128 cbc hmac-md5无

debug1:SSH2\u MSG\u KEX\u DH\u GEX\u请求(1024您的授权密钥行应该是

AuthorizedKeysFile     %h/.ssh/authorized_keys

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

尝试从~/.ssh/known_主机中删除box1 IP,因此它将续订。可能是ssh由于可能的“中间人”攻击而禁用密钥身份验证

如果没有帮助,请添加行

GSSAPIA认证号

在您的/etc/ssh/ssh_配置文件中。

我认为此链接将解决您的问题,我使用它来解决我的ssh非登录问题。关键是运行 sshroot@node02'restorecon-R-v/root/.ssh' 此命令将修复SE

更新-修复它

restorecon -R -v -d /root/.ssh
这是RH的一个已知问题,其中目录被错误标记,并且当作为init脚本运行时,PAM会阻止sshd读取授权的\u主机。如果您偶然发现
/var/log/audit/audit.log
,您会看到错误。这种情况很少见,但发生时很痛苦

详情请浏览

原创帖子

restorecon -R -v -d /root/.ssh
我刚刚遇到了这个问题。我的VirtualBox调优得很差(我没有告诉vbox使用64位)——当我克隆并重新启动(在vbox RedHat 64位模式下)时,它开始向我询问密码

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

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

所以这是一个/etc/init.d/sshd问题。但是我还没能找到它是什么…我试着扔掉了脚本中的大部分内容,但是当作为
/etc/init.d/sshd start
调用时,它仍然提示输入密码,但在
/usr/sbin/sshd
时就没有了


也许这些评论会有所帮助,然后有人会进一步提供帮助!?

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

我曾经为~/.ssh做过一次:

drwx-----2构建4096年11月4日14:35

drwx-----6构建4096 11月4日14:34

-rw-----1构建400 11月4日14:35授权密钥

成功了


谢谢。达米安,我也有同样的问题,整个下午都在挠头。 结果是一个小的sshd_配置文件问题

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

chmod 700 ~/.ssh
接下来,转到/etc/ssh/sshd\u config,将
StrictModes yes
更改为
StrictModes no
。如果注释掉了,则专门将
StrictModes no
添加到文件中。


这就解决了问题。

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

您为哪个用户设置了授权密钥。在远程框上,它需要为您尝试连接的用户设置。root的授权密钥不适用于所有用户。您是否更改了框2的ssh\u配置,以便ssh尝试进行公钥身份验证?此外,我将使用-v运行scp标记以获取详细输出。这对调试非常有帮助。如何更改配置以尝试pubkey?感谢您的捕获。我对我的/etc/ssh/sshd_config进行了更改,并重新启动了/sbin/service sshd restart,但我仍然无法连接。他的调试输出没有提到GSS。我认为这不是问题所在。