2

I am trying to SSH into a running EC2 instance but it gives the following error every time.

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 (most recent call last): File "/home/.../FirstModule.py", line 26, in cmd.shell() File "/usr/lib/python2.7/dist-packages/boto/manage/cmdshell.py", line 114, in shell interactive_shell(channel) File "/usr/lib/python2.7/dist-packages/boto/mashups/interactive.py", line 34, in interactive_shell posix_shell(chan) File "/usr/lib/python2.7/dist-packages/boto/mashups/interactive.py", line 42, in posix_shell oldtty = termios.tcgetattr(sys.stdin) termios.error: (22, 'Invalid argument')

Any clue why this error is showing up?

4

1 に答える 1

1

One possibility is that the path name to the hosts file is not a raw string. It might help to do it as follows:

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

You might also want to quote the key_dir value as well.

key_dir = r'~/'
于 2012-11-13T17:28:32.727 に答える