fixed ssh issue

This commit is contained in:
n0mad1k
2025-05-12 12:13:34 -04:00
parent e1666a0124
commit 140dbe6619
+21 -10
View File
@@ -1167,13 +1167,18 @@ def create_consistent_resource_names(config):
config['c2_name'] = f"s-{deployment_id}" config['c2_name'] = f"s-{deployment_id}"
config['tracker_name'] = f"t-{deployment_id}" config['tracker_name'] = f"t-{deployment_id}"
# Ensure SSH key follows same pattern # Ensure SSH key follows same pattern with provider-specific extension
if not config.get('ssh_key'): if not config.get('ssh_key'):
if config.get('provider') == 'aws':
config['ssh_key'] = os.path.expanduser(f"~/.ssh/c2deploy_{deployment_id}.pem")
else:
config['ssh_key'] = os.path.expanduser(f"~/.ssh/c2deploy_{deployment_id}") config['ssh_key'] = os.path.expanduser(f"~/.ssh/c2deploy_{deployment_id}")
# Set consistent public key path # Set consistent public key path
if config.get('ssh_key'): if config.get('ssh_key'):
config['ssh_key_path'] = f"{config['ssh_key']}.pub" if config.get('provider') == 'aws' and not config['ssh_key'].endswith('.pem'):
config['ssh_key'] = f"{config['ssh_key']}.pem"
config['ssh_key_path'] = f"{config['ssh_key'].replace('.pem', '')}.pub"
# Set other resource names with the same deployment ID # Set other resource names with the same deployment ID
config['vpc_name'] = f"vpc-{deployment_id}" config['vpc_name'] = f"vpc-{deployment_id}"
@@ -1607,15 +1612,21 @@ def ssh_to_instance(config):
print(f"{COLORS['RED']}No IP address found for {instance_type}. Cannot SSH.{COLORS['RESET']}") print(f"{COLORS['RED']}No IP address found for {instance_type}. Cannot SSH.{COLORS['RESET']}")
return False return False
# Get SSH key and user # Get SSH key and user - with AWS-specific handling
ssh_key = config.get('ssh_key') ssh_key = config.get('ssh_key')
if not ssh_key: if config.get('provider') == 'aws':
# For AWS, check for deployment_id specific keys with .pem extension # For AWS, always look for the .pem extension key
if config.get('provider') == 'aws' and config.get('deployment_id'): deployment_id = config.get('deployment_id', '')
potential_key = os.path.expanduser(f"~/.ssh/c2deploy_{config.get('deployment_id')}.pem") aws_key_path = os.path.expanduser(f"~/.ssh/c2deploy_{deployment_id}.pem")
if os.path.exists(potential_key): if os.path.exists(aws_key_path):
ssh_key = potential_key ssh_key = aws_key_path
logging.info(f"Found AWS key at {ssh_key}") logging.info(f"Using AWS key at {ssh_key}")
else:
# Try adding .pem to existing key path if it exists
potential_pem_key = f"{ssh_key}.pem" if ssh_key else ""
if potential_pem_key and os.path.exists(potential_pem_key):
ssh_key = potential_pem_key
logging.info(f"Found AWS key with .pem extension: {ssh_key}")
if not ssh_key: if not ssh_key:
logging.error("No SSH key specified") logging.error("No SSH key specified")