Amazon web services 尝试使用boto.manage.cmdshell SSH到运行EC2的实例时出错
我试图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
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'~/'