douyun1546 2018-05-25 12:39
浏览 100

无法使用Laravel 5.5中的SSH密钥连接到远程服务器?

I am trying to connect with remote server using SSH Key. I am generating SSH keypair using phpseclib 2.0 and I storing keys in the database. Here is how I am trying to connect.

Config::set('remote.connections.production.host',$server->ip);
Config::set('remote.connections.production.username',$server->username);
Config::set('remote.connections.production.keytext',$server->meta()->where('meta_key','private_key')->first()->meta_value);

I have public key corresponding to the private key I am using in remote server's ~/.ssh/authorized_keys file. The permissions for .ssh directory is 700 and permissions for authorized_keys is 600 which is perfect.

First I thought this might be a issue but then I tried to remove all from the private key before connecting but I am still getting unable to connect to remote server. I don't know where the issue is. I am trying since last two days without luck.

I think SSH key gets damaged once it enters into the database. Here is how I am generating and storing SSH keypair in the database.

$rsa = new RSA();
$rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH);
$keys = $rsa->createKey(2048);
$privateKey = $keys['privatekey'];
$publicKey = $keys['publickey'];

$server->meta()->create([
     'meta_key' => 'private_key',
     'meta_value' => $privateKey
]);

$server->meta()->create([
    'meta_key' => 'public_key',
    'meta_value' => $publicKey
]);

Any help would be appreciated. Keys are being generated for sure because I can see it in the database.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog