无密码root登录从aws ec2到ec2

时间:2015-09-11 18:25:12

标签: linux ssh amazon-ec2

我正在尝试在3个ec2实例(node1,node2,node3)上启动一个vertica集群,这需要通过实例之间的ssh进行root登录。

在node1上,主节点...作为root用户,我使用g = {[2015, 4]=>90, [2015, 5]=>133, [2015, 6]=>131, [2015, 7]=>28, [2015, 8]=>45, [2015, 9]=>6} h = g.keys.sort.each_with_object(Hash.new(0)) {|k,h| h[k]=g[k]+ h[previous(k)]} #=> {[2015, 4]=>90, [2015, 5]=>223, [2015, 6]=>354, [2015, 7]=>382, # [2015, 8]=>427, [2015, 9]=>433} h.update(h) { |_,v| round_to_nearest(v, 5) } #=> {[2015, 4]=>90, [2015, 5]=>225, [2015, 6]=>355, [2015, 7]=>380, # [2015, 8]=>425, [2015, 9]=>435} def previous((year, month)) month -= 1 (year -=1; month = 12) if month.zero? [year, month] end def round_to_nearest(n, d) d*(n/d.to_f).round end

生成密钥

在node2和node3上,我编辑了ssh-keygen文件:

/etc/ssh/sshd_config

然后将id_rsa.pub密钥添加到RSAAuthentication yes PubkeyAuthentication yes PasswordAuthentication no` /root/.ssh/authorized_keys

中的node2和node3

然后做了

/home/ec2-user/.ssh/authorized_keys

我尝试从node1登录service sshd restart ...但我一直收到此错误:

ssh root@node2

编辑:

还将permitrootlogin更改为:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

在ssh上做了-v,这是我看到的

PermitRootLogin without-password

我看到它试图使用id_dsa ...但是我没有那个文件...我有一个名为 [root@ip-10-205-119-236 .ssh]# ssh -v root@10.205.117.61 OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug1: Connecting to 10.205.117.61 [10.205.117.61] port 22. debug1: Connection established. debug1: permanently_set_uid: 0/0 debug1: identity file /root/.ssh/identity type -1 debug1: identity file /root/.ssh/identity-cert type -1 debug1: identity file /root/.ssh/id_rsa type -1 debug1: identity file /root/.ssh/id_rsa-cert type -1 debug1: identity file /root/.ssh/id_dsa type -1 debug1: identity file /root/.ssh/id_dsa-cert type -1 debug1: identity file /root/.ssh/id_ecdsa type -1 debug1: identity file /root/.ssh/id_ecdsa-cert type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3 debug1: match: OpenSSH_5.3 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_5.3 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: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<2048<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 debug1: Host '10.205.117.61' is known and matches the RSA host key. debug1: Found key in /root/.ssh/known_hosts:1 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,gssapi-keyex,gssapi-with-mic debug1: Next authentication method: gssapi-keyex debug1: No valid Key exchange context debug1: Next authentication method: gssapi-with-mic debug1: Unspecified GSS failure. Minor code may provide more information Credentials cache file '/tmp/krb5cc_0' not found debug1: Unspecified GSS failure. Minor code may provide more information Credentials cache file '/tmp/krb5cc_0' not found debug1: Unspecified GSS failure. Minor code may provide more information debug1: Unspecified GSS failure. Minor code may provide more information Credentials cache file '/tmp/krb5cc_0' not found debug1: Next authentication method: publickey debug1: Trying private key: /root/.ssh/identity debug1: Trying private key: /root/.ssh/id_rsa debug1: read PEM private key done: type RSA debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic debug1: Trying private key: /root/.ssh/id_dsa debug1: Trying private key: /root/.ssh/id_ecdsa debug1: No more authentication methods to try. Permission denied (publickey,gssapi-keyex,gssapi-with-mic). 的文件,这就是我命名的文件......

1 个答案:

答案 0 :(得分:0)

SSH要求对这些文件具有非常精确的访问权限,因为如果它们不同,则存在安全问题。您需要~/.ssh只能由您访问,authorized_keys无法由其他人编写:

chmod 700 ~/.ssh
chmod 644 ~/.ssh/authorized_keys

应该修复它。