feat: ssh私钥支持设置密码

This commit is contained in:
耗子 2025-11-10 23:17:36 +08:00
parent 17ffe5704f
commit 3e2b8396fa
No known key found for this signature in database
GPG Key ID: C964D7226D045DAA
2 changed files with 10 additions and 2 deletions

View File

@ -2273,6 +2273,12 @@ ctrl+x 保存退出',
'required' => true,
'show' => 'auth==1',
],
'passphrase' => [
'name' => '私钥密码',
'type' => 'input',
'placeholder' => '若私钥有设置密码,请填写此项',
'show' => 'auth==1',
],
'windows' => [
'name' => '是否Windows',
'type' => 'radio',

View File

@ -2,6 +2,7 @@
namespace app\lib\deploy;
use app\lib\CertHelper;
use app\lib\DeployInterface;
use Exception;
@ -49,7 +50,7 @@ class ssh implements DeployInterface
fclose($stream);
$this->log('私钥已保存到:' . $config['pem_key_file']);
} elseif ($config['format'] == 'pfx') {
$pfx = \app\lib\CertHelper::getPfx($fullchain, $privatekey, $config['pfx_pass'] ? $config['pfx_pass'] : null);
$pfx = CertHelper::getPfx($fullchain, $privatekey, $config['pfx_pass'] ? $config['pfx_pass'] : null);
$stream = fopen("ssh2.sftp://$sftp{$config['pfx_file']}", 'w');
if (!$stream) {
@ -157,7 +158,8 @@ class ssh implements DeployInterface
file_put_contents($privateKeyPath, $this->config['privatekey']);
file_put_contents($publicKeyPath, $publicKey);
umask($umask);
if (!ssh2_auth_pubkey_file($connection, $this->config['username'], $publicKeyPath, $privateKeyPath)) {
$passphrase = $this->config['passphrase'] ?? null; // 私钥密码
if (!ssh2_auth_pubkey_file($connection, $this->config['username'], $publicKeyPath, $privateKeyPath, $passphrase)) {
throw new Exception('私钥认证失败');
}
} else {