What potential security risks should be considered when using SSH connections in PHP?

When using SSH connections in PHP, one potential security risk to consider is exposing sensitive information, such as usernames and passwords, in the code. To mitigate this risk, it is recommended to store sensitive information in environment variables or configuration files outside of the codebase.

// Store sensitive information in environment variables
$ssh_username = getenv('SSH_USERNAME');
$ssh_password = getenv('SSH_PASSWORD');

// Use the stored credentials in your SSH connection code
$connection = ssh2_connect('example.com', 22);
ssh2_auth_password($connection, $ssh_username, $ssh_password);