TestSSH2.php 977 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. define('APP_ID', 'test');
  4. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  5. require_once(BASE_ROOT_PATH . '/global.php');
  6. require_once(BASE_CORE_PATH . '/lrlz.php');
  7. require_once(BASE_ROOT_PATH . '/fooder.php');
  8. function my_ssh_disconnect($reason, $message, $language) {
  9. printf("Server disconnected with reason code [%d] and message: %s\n",
  10. $reason, $message);
  11. }
  12. class TestSSH2 extends TestCase
  13. {
  14. public static function setUpBeforeClass(): void
  15. {
  16. // Base::run_util();
  17. }
  18. public function testConnect()
  19. {
  20. $connection = ssh2_connect('121.89.223.81', 22, ['hostkey'=>'ssh-rsa']);
  21. if (ssh2_auth_pubkey_file($connection, 'root',
  22. '/home/root/.ssh/id_rsa.pub',
  23. '/home/root/.ssh/id_rsa', '')) {
  24. echo "Public Key Authentication Successful\n";
  25. } else {
  26. die('Public Key Authentication Failed');
  27. }
  28. }
  29. }