# File lib/rudy/cli/aws/ec2/candy.rb, line 60
 60:     def ssh
 61:       opts = {}
 62:       opts[:group] = @option.group if @option.group
 63:       opts[:group] = :any if @option.all
 64:       opts[:id] = @option.instid if @option.instid
 65:       
 66:       # Options to be sent to Rye::Box
 67:       rye_opts = { :user => @global.user || Rudy.sysinfo.user, :debug => nil, :info => STDOUT  }
 68:       if @@global.pkey 
 69:         raise "Cannot find file #{@@global.pkey}" unless File.exists?(@@global.pkey)
 70:         raise InsecureKeyPermissions, @@global.pkey unless File.stat(@@global.pkey).mode == 33152
 71:         rye_opts[:keys] = @@global.pkey 
 72:       end
 73:       
 74:       
 75:       # The user specified a command to run. We won't create an interactive
 76:       # session so we need to prepare the command and its arguments
 77:       if @argv.first
 78:         command, command_args = @argv.shift, @argv || []
 79:         li "#{command} #{command_args.join(' ')}" if @@global.verbose > 1
 80:       
 81:       # otherwise, we'll open an ssh session or print command
 82:       else
 83:         command, command_args = :interactive_ssh, @option.print.nil?
 84:       end
 85:       
 86:       checked = false
 87:       lt = Rudy::AWS::EC2::Instances.list_group(opts[:group], :running, opts[:id]) do |inst|
 88:         
 89:         # Print header
 90:         if @@global.quiet
 91:           print "You are #{rye_opts[:user].bright}. " if !checked # only the 1st
 92:         else
 93:           print "Connecting #{rye_opts[:user].bright}@#{inst.dns_public} "
 94:           li "(#{inst.awsid}, groups: #{inst.groups.join(', ')})"
 95:         end
 96:         
 97:         # Make sure we want to run this command on all instances
 98:         if !checked && command != :interactive_ssh 
 99:           execute_check(:medium) if rye_opts[:user] == "root"
100:           checked = true
101:         end
102:         
103:         # Open the connection and run the command
104:         rbox = Rye::Box.new(inst.dns_public, rye_opts)
105:         ret = rbox.send(command, command_args)
106:         li ret unless command == :interactive_ssh
107:       end
108:     end