首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用刀子ec2插件在私有网络私有子网中创建虚拟机

使用刀子ec2插件在私有网络私有子网中创建虚拟机
EN

Stack Overflow用户
提问于 2013-05-09 07:14:28
回答 1查看 4.9K关注 0票数 17

虽然我写了相当多的chef,但我对AWS/VPC和管理网络流量(特别是堡垒主机)都是相当陌生的。

使用刀子ec2插件,我希望能够从我的开发人员工作站动态创建和引导虚拟机。虚拟机应该能够存在于我的私有网络的公有或私有子网中。我希望在不使用弹性IP的情况下完成所有这些工作。我还希望我的堡垒主机不插手(即,我希望避免在我的堡垒主机上创建显式的每虚拟机监听隧道)

我已经成功地使用刀子ec2插件在传统EC2模型中创建了虚拟机(例如,在我的VPC之外)。我正在尝试在我的私有网络中创建一个实例。在knife命令行上,我指定了一个网关、安全组、子网等。创建了VM,但之后knife无法通过ssh连接到它。

下面是我的刀子命令行:

代码语言:javascript
复制
knife ec2 server create \
    --flavor t1.micro \
    --identity-file <ssh_private_key> \
    --image ami-3fec7956 \
    --security-group-ids sg-9721e1f8 \
    --subnet subnet-e4764d88 \
    --ssh-user ubuntu \
    --server-connect-attribute private_ip_address \
    --ssh-port 22 \
    --ssh-gateway <gateway_public_dns_hostname (route 53)> \
    --tags isVPC=true,os=ubuntu-12.04,subnet_type=public-build-1c \
    --node-name <VM_NAME>

我怀疑我的问题与我的堡垒主机的配置有关。在谷歌搜索了一天之后,我找不到一个有效的配置。我可以通过ssh连接到堡垒主机,然后从那里通过ssh连接到新创建的VM。我不能使用网关参数让knife成功地复制它。

我已经尝试过/etc/ssh/ssh_config。以下是它今天的存在方式:

代码语言:javascript
复制
    ForwardAgent yes
#ForwardX11 no
#ForwardX11Trusted yes
#RhostsRSAAuthentication no
#RSAAuthentication yes
#PasswordAuthentication no
#HostbasedAuthentication yes
#GSSAPIAuthentication no
#GSSAPIDelegateCredentials no
#GSSAPIKeyExchange no
#GSSAPITrustDNS no
#BatchMode no
   CheckHostIP no
#AddressFamily any
#ConnectTimeout 0
    StrictHostKeyChecking no
    IdentityFile ~/.ssh/identity
#IdentityFile ~/.ssh/id_rsa
#IdentityFile ~/.ssh/id_dsa
#Port 22
#Protocol 2,1
#Cipher 3des
#Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
#MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
#EscapeChar ~
    Tunnel yes
#TunnelDevice any:any
#PermitLocalCommand no
#VisualHostKey no
#ProxyCommand ssh -q -W %h:%p gateway.example.com
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes
    GSSAPIDelegateCredentials no
    GatewayPorts yes

我还将/home/ubuntu/.ssh/identity设置为我的新实例的匹配私钥。

更新:

我注意到堡垒主机的/var/log/auth.log中有以下内容:

代码语言:javascript
复制
May  9 12:15:47 ip-10-0-224-93 sshd[8455]: Invalid user  from <WORKSTATION_IP>
May  9 12:15:47 ip-10-0-224-93 sshd[8455]: input_userauth_request: invalid user  [preauth]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-09 21:28:07

我终于解决了这个问题。指定网关时缺少用户名。我最初认为--ssh-user参数将用于网关和我试图引导的VM。这是不正确的,必须为这两个都指定用户名。

代码语言:javascript
复制
knife ec2 server create \
    --flavor t1.micro \
    --identity-file <ssh_private_key> \
    --image ami-3fec7956 \
    --security-group-ids sg-9721e1f8 \
    --subnet subnet-e4764d88 \
    --ssh-user ubuntu \
    --server-connect-attribute private_ip_address \
    --ssh-port 22 \
    --ssh-gateway ubuntu@<gateway_public_dns_hostname (route 53)> \
    --tags isVPC=true,os=ubuntu-12.04,subnet_type=public-build-1c \
    --node-name <VM_NAME>

只需要包含更新的那一行(注意前面的ubuntu@ ):

代码语言:javascript
复制
    --ssh-gateway ubuntu@<gateway_public_dns_hostname (route 53)>

我现在已经检查并锁定了我的堡垒主机,包括删除/home/ubuntu/.ssh/identity,因为在堡垒主机上存储私钥真的很困扰我。

仅供参考:在设置堡垒主机时,sshd的“开箱即用”配置将在使用Amazon Linux AMI镜像时起作用。此外,上面的一些参数是可选的,例如--ssh-port。

票数 15
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16451762

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档