我正在尝试通过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()
追踪(最近一次通话): 文件“/home/.../FirstModule.py”,第26行,cmd.shell() 文件“/usr/lib/python2.7/dist-packages/boto/manage/cmdshell.py”,第114行,在shell中 interactive_shell(通道) 在Interactive_shell中输入文件“/usr/lib/python2.7/dist-packages/boto/mashups/interactive.py”,第34行 posix_shell(陈) 文件“/usr/lib/python2.7/dist-packages/boto/mashups/interactive.py”,第42行,在posix_shell中 oldtty = termios.tcgetattr(sys.stdin) termios.error:(22,'无效参数')
为什么会出现此错误?
答案 0 :(得分:1)
一种可能性是hosts文件的路径名不是原始字符串。它可能有助于如下:
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'~/'