persistent_ssh_agent package

class persistent_ssh_agent.PersistentSSHAgent(config: SSHConfig | None = None, expiration_time: int = 86400, reuse_agent: bool = True)[源代码]

基类:object

Handles persistent SSH agent operations and authentication.

This class manages SSH agent persistence across sessions by saving and restoring agent information. It also handles SSH key management and authentication for various operations including Git.

SSH_DEFAULT_KEY = 'id_rsa'
SSH_DEFAULT_OPTIONS = {'StrictHostKeyChecking': 'no'}
SSH_KEY_TYPES = ['id_ed25519', 'id_ecdsa', 'id_ecdsa_sk', 'id_ed25519_sk', 'id_rsa', 'id_dsa']
get_git_ssh_command(hostname: str) str | None[源代码]

Generate Git SSH command with proper configuration.

参数:

hostname -- Target Git host

返回:

SSH command string if successful, None on error

is_valid_hostname(hostname: str) bool[源代码]

Check if a hostname is valid according to RFC 1123 and supports IPv6.

参数:

hostname -- The hostname to validate

返回:

True if the hostname is valid, False otherwise

返回类型:

bool

备注

  • Maximum length of 255 characters

  • Can contain letters (a-z), numbers (0-9), dots (.) and hyphens (-)

  • Cannot start or end with a dot or hyphen

  • Labels (parts between dots) cannot start or end with a hyphen

  • Labels cannot be longer than 63 characters

  • IPv6 addresses are supported (with or without brackets)

static run_command(command: List[str], shell: bool = False, check_output: bool = True, timeout: int | None = None, env: Dict[str, str] | None = None) CompletedProcess | None[源代码]

Run a command and return its output.

参数:
  • command -- Command and arguments to run

  • shell -- Whether to run command through shell

  • check_output -- Whether to capture command output

  • timeout -- Command timeout in seconds

  • env -- Environment variables for command

返回:

CompletedProcess object if successful, None on error

返回类型:

CompletedProcess

setup_ssh(hostname: str) bool[源代码]

Set up SSH authentication for a host.

参数:

hostname -- Hostname to set up SSH for

返回:

True if setup successful

返回类型:

bool

class persistent_ssh_agent.SSHConfig(identity_file: str | None = None, identity_content: str | None = None, identity_passphrase: str | None = None, ssh_options: Dict[str, str] = None)[源代码]

基类:object

SSH configuration class.

identity_content: str | None = None
identity_file: str | None = None
identity_passphrase: str | None = None
ssh_options: Dict[str, str] = None

Submodules