What security considerations should be taken into account when using SSH connections in PHP?

When using SSH connections in PHP, it is important to ensure that the connection is secure to prevent unauthorized access to sensitive information. This can be achieved by using key-based authentication instead of password authentication, as keys are more secure. Additionally, it is recommended to restrict the SSH user's permissions to only necessary actions to minimize the risk of potential security breaches.

// Example of establishing an SSH connection with key-based authentication
$connection = ssh2_connect('example.com', 22);
ssh2_auth_pubkey_file($connection, 'username', '/path/to/public_key', '/path/to/private_key');