Hướng dẫn divineomega php ssh connection - kết nối ssh của Divineomega php

Kết nối PHP SSH

Hướng dẫn divineomega php ssh connection - kết nối ssh của Divineomega php
Hướng dẫn divineomega php ssh connection - kết nối ssh của Divineomega php

Gói kết nối PHP SSH cung cấp một cú pháp thanh lịch để kết nối với các máy chủ SSH và thực thi các lệnh.Nó hỗ trợ cả mật khẩu và xác thực bàn phím công cộng công cộng và có thể dễ dàng nắm bắt đầu ra và lỗi lệnh.

Cài đặt

Bạn có thể cài đặt gói kết nối PHP SSH bằng cách chạy lệnh trình soạn thảo sau.

composer require divineomega/php-ssh-connection

Cách sử dụng

Xem các hướng dẫn sử dụng cơ bản sau đây.

$connection = (new SSHConnection())
            ->to('test.rebex.net')
            ->onPort(22)
            ->as('demo')
            ->withPassword('password')
         // ->withPrivateKey($privateKeyPath)
         // ->timeout(0)
            ->connect();

$command = $connection->run('echo "Hello world!"');

$command->getOutput();  // 'Hello World'
$command->getError();   // ''

$connection->upload($localPath, $remotePath);
$connection->download($remotePath, $localPath);

Để bảo mật, bạn có thể lấy dấu vân tay máy chủ từ xa và xác minh dấu vân tay vẫn giống nhau trên mỗi kết nối tiếp theo.

$fingerprint = $connection->fingerprint();

if ($newConnection->fingerprint() != $fingerprint) {
    throw new Exception('Fingerprint does not match!');
}

Nếu bạn muốn, bạn có thể chỉ định loại dấu vân tay bạn muốn truy xuất.

$md5Fingerprint  = $connection->fingerprint(SSHConnection::FINGERPRINT_MD5); // default
$sha1Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_SHA1);

Kết nối PHP SSH

Gói kết nối PHP SSH cung cấp một cú pháp thanh lịch để kết nối với các máy chủ SSH và thực thi các lệnh.Nó hỗ trợ cả mật khẩu và xác thực bàn phím công cộng công cộng và có thể dễ dàng nắm bắt đầu ra và lỗi lệnh.

Cài đặt

Bạn có thể cài đặt gói kết nối PHP SSH bằng cách chạy lệnh trình soạn thảo sau.

composer require divineomega/php-ssh-connection

Cách sử dụng

Xem các hướng dẫn sử dụng cơ bản sau đây.

$connection = (new SSHConnection())
            ->to('test.rebex.net')
            ->onPort(22)
            ->as('demo')
            ->withPassword('password')
         // ->withPrivateKey($privateKeyPath)
         // ->timeout(0)
            ->connect();

$command = $connection->run('echo "Hello world!"');

$command->getOutput();  // 'Hello World'
$command->getError();   // ''

$connection->upload($localPath, $remotePath);
$connection->download($remotePath, $localPath);

Để bảo mật, bạn có thể lấy dấu vân tay máy chủ từ xa và xác minh dấu vân tay vẫn giống nhau trên mỗi kết nối tiếp theo.

$fingerprint = $connection->fingerprint();

if ($newConnection->fingerprint() != $fingerprint) {
    throw new Exception('Fingerprint does not match!');
}

Nếu bạn muốn, bạn có thể chỉ định loại dấu vân tay bạn muốn truy xuất.

$md5Fingerprint  = $connection->fingerprint(SSHConnection::FINGERPRINT_MD5); // default
$sha1Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_SHA1);