Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 尝试使用boto.manage.cmdshell SSH到运行EC2的实例时出错_Amazon Web Services_Python 2.7_Boto - Fatal编程技术网

Amazon web services 尝试使用boto.manage.cmdshell SSH到运行EC2的实例时出错

Amazon web services 尝试使用boto.manage.cmdshell SSH到运行EC2的实例时出错,amazon-web-services,python-2.7,boto,Amazon Web Services,Python 2.7,Boto,我试图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) re

我试图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()
回溯(最近一次呼叫最后一次): cmd.shell()中的文件“/home/../FirstModule.py”,第26行 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,“无效参数”)


出现此错误的任何线索?

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

cmd = boto.manage.cmdshell.sshclient_from_instance(
          instance,
          key_path,
          host_key_file=r'~/.ssh/known_hosts',
          user_name='ec2-user'
       )
您可能还需要引用
键\u dir

key_dir = r'~/'