【问题标题】:Error when trying to SSH into an EC2 running instance using boto.manage.cmdshell尝试使用 boto.manage.cmdshell SSH 到 EC2 运行实例时出错
【发布时间】:2012-11-08 20:36:51
【问题描述】:

我正在尝试通过 SSH 连接到正在运行的 EC2 实例,但每次都会出现以下错误。

import os
import boto.manage.cmdshell

ec2 = boto.connect_ec2()
key_dir= '~/'
key_name='keypair'
key_extension='.pem'
key_path = os.path.join(os.path.expanduser(key_dir),
                    key_name+key_extension)
reservations = ec2.get_all_instances()
instance = reservations[0].instances[0]

cmd = boto.manage.cmdshell.sshclient_from_instance(instance,
                                               key_path,
                                               host_key_file='~/.ssh/known_hosts',
                                               user_name='ec2-user')

cmd.shell()

Traceback(最近一次调用最后一次): 文件“/home/.../FirstModule.py”,第 26 行,在 cmd.shell() 文件“/usr/lib/python2.7/dist-packages/boto/manage/cmdshell.py”,第 114 行,在 shell 交互式外壳(通道) 文件“/usr/lib/python2.7/dist-packages/boto/mashups/interactive.py”,第 34 行,interactive_shell posix_shell(chan) posix_shell 中的文件“/usr/lib/python2.7/dist-packages/boto/mashups/interactive.py”,第 42 行 oldtty = termios.tcgetattr(sys.stdin) termios.error: (22, '无效参数')

知道为什么会出现这个错误吗?

【问题讨论】:

    标签: amazon-web-services python-2.7 boto


    【解决方案1】:

    一种可能性是主机文件的路径名不是原始字符串。这样做可能会有所帮助:

    cmd = boto.manage.cmdshell.sshclient_from_instance(
              instance,
              key_path,
              host_key_file=r'~/.ssh/known_hosts',
              user_name='ec2-user'
           )
    

    您可能还想引用key_dir 值。

    key_dir = r'~/'
    

    【讨论】:

      猜你喜欢
      • 2014-03-28
      • 2021-05-29
      • 2018-11-28
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 2011-08-26
      • 2023-03-21
      • 2013-06-04
      相关资源
      最近更新 更多