MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / SshAgentStartCommand

Class SshAgentStartCommand

keepercommander/commands/ssh_agent.py:838–882  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

836
837
838class SshAgentStartCommand(Command):
839 def get_parser(self):
840 return ssh_agent_start_parser
841
842 def is_authorised(self):
843 return True
844
845 def execute(self, params, **kwargs):
846 if params.ssh_agent is None:
847 params.ssh_agent = SshAgentContext()
848 params.ssh_agent.keys = [x for x in params.ssh_agent.keys if x.record_uid]
849 print(Style.BRIGHT + 'Starting Commander in SSH Agent Mode...' + Style.RESET_ALL)
850 print('Loading keys...')
851 params.ssh_agent.load_private_keys(params)
852 params.ssh_agent.start(params.user)
853 print(f'Loaded {len(params.ssh_agent.keys)} private key(s)')
854 print('\033[2K' + Fore.LIGHTGREEN_EX + 'SSH Agent Started.' + Style.RESET_ALL)
855 if os.name == 'posix':
856 print(Fore.CYAN)
857 print('Note: To use the Commander SSH Agent, run the below command in your terminal or startup file:')
858 print(f'export SSH_AUTH_SOCK={params.ssh_agent.path}')
859 print(Style.RESET_ALL)
860 if params.batch_mode:
861 log_command = SshAgentLogCommand()
862 help_printed = False
863 while True:
864 answer = user_choice('Commander SSH Agent', '?lq', show_choice=False)
865 if not answer:
866 if not help_printed:
867 help_printed = True
868 answer = '?'
869 else:
870 continue
871
872 if answer == '?':
873 print('{0:>12} : {1}'.format('?', 'Print this help'))
874 print('{0:>12} : {1}'.format('(l)og', 'SSH Agent agent logs'))
875 print('{0:>12} : {1}'.format('(q)uit', 'Quit'))
876 elif answer.lower() in {'l', 'log'}:
877 log_command.execute(params)
878 elif answer.lower() in {'q', 'quit'}:
879 params.ssh_agent.stop()
880 break
881 else:
882 print(f'Command \"{answer}\" is not recognized')
883
884
885class SshAgentStopCommand(Command):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected